Tag: 数据源

我如何创build一个具有两个数据源的UITableView

我有一个UITableView的UIViewController。 但是那个tableView有两个数据源。 基本上UIButton会决定哪个数据源是活动的。 我该怎么做? 没有这样的方法 [self.tableView reloadData:myDataSourceArray]; 这将有助于区分使用哪个数据源以及使用哪个UITableViewCell扩展。 那么我该怎么办呢? 我说button保持简单,但实际上,dataSource_1是从服务器预加载,而dataSource_2是由UISearchBar加载的。

无效更新:第0节UITableView中的行数无效

我知道这已经被问过50次,但我已经通过所有其他的答案,并没有发现任何可以解决我的问题。 无论如何,这是我的代码: NSMutableArray *cellIndicesToBeDeleted = [[NSMutableArray alloc] init]; for (int i = 0; i < [thetableView numberOfRowsInSection:0]; i++) { NSIndexPath *p = [NSIndexPath indexPathForRow:i inSection:0]; if ([[thetableView cellForRowAtIndexPath:p] accessoryType] == UITableViewCellAccessoryCheckmark) { [cellIndicesToBeDeleted addObject:p]; [self.cellArray removeObjectAtIndex:i]; } } [thetableView deleteRowsAtIndexPaths:cellIndicesToBeDeleted withRowAnimation:UITableViewRowAnimationLeft]; [cellIndicesToBeDeleted release]; 当我执行这个代码时,我得到这个崩溃日志: Invalid update: invalid number of rows in section 0. The number […]

Objective-c UITableView单独的类cellForRowAtIndexPath不会被调用

关于这个主题的问题有很多,但我还没有碰到我的用例,所以在这里。 这是我在OBJ-C的第一个几周,所以我不知道我在做些什么… 我想要的是 我并不是特别喜欢在OBJ-C中看到这么多的类,使用这个地球上的每一个函数来重载视图控制器类。 它看起来肮脏,并感到严重的OOP去。 在我的使用情况下,我没有一个全屏幕的桌子只是一个小东西来保存10件事情。 因此,使用完整的UITableViewController是不合适的。 相反,我想让我所有的表代表特定的方法在UITableView子类。 不在UITableViewController或具有UITableView属性的ViewController中。 这应该是简单而又… 问题 无论我做什么我似乎无法获取方法cellForRowAtIndexPath触发。 我知道足够的知道,这东西很大程度上依赖于委托和数据源分配…但是,因为我有一个单独的UITableView类使用<UITableViewDelegate, UITableViewDataSource>委托,我不认为我应该做任何forms的任务根本! 我要写什么? self.delegate = self ? 或者更糟的是,在调用这个UITableView类的ViewController中, self.tasksTable.delgate = self.tasksTable ? 呃…毛 这是我在做的代码。 代码 TasksTableView.h #import <UIKit/UIKit.h> @interface TasksTableView : UITableView <UITableViewDelegate, UITableViewDataSource> { NSArray *tasksData; } – (NSMutableArray *)getAllTasks; @end TasksTableView.m #import "TasksTableView.h" #import "NSObject+RemoteFetch.h" //<–I use this to fetch, obvs […]

在UITableView中处理UIButton Photo Grid的最有效方法是什么?

我有一个iOS应用程序正在从一个JSON请求从一个MySQL数据库抓取一堆照片URL。 一旦我有这些照片和相关信息,我用它来填充UITableView的数据源。 我想创build一个UIButtons网格,由照片制成,每行4个。 这个当前的代码工作,但它非常慢,我的电话/模拟器冻结了,当我滚动表。 只有几行的表格可以正常工作,但是一旦达到10行或更多行,它就会慢慢下降,并且接近崩溃。 我是iOS和Objective-C的新手,所以我认为在代码中效率低下。 有什么build议么? 谢谢!! – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; static NSString *CompViewCellIdentifier = @"CompViewCellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CompViewCellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CompViewCellIdentifier] autorelease]; } // The photo number in the photos array that we'll need […]

将数据源分隔到Swift中的另一个类

我试图保持我的视图控制器干净,如本文所述objc.io问题#1更轻的视图控制器 。 我在Objective-C中testing了这个方法,它工作正常。 我有一个单独的类实现UITableViewDataSource方法。 #import "TableDataSource.h" @interface TableDataSource() @property (nonatomic, strong) NSArray *items; @property (nonatomic, strong) NSString *cellIdentifier; @end @implementation TableDataSource – (id)initWithItems:(NSArray *)items cellIdentifier:(NSString *)cellIdentifier { self = [super init]; if (self) { self.items = items; self.cellIdentifier = cellIdentifier; } return self; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.items.count; } – (UITableViewCell *)tableView:(UITableView […]

Firebase数据库不等于请求 – 替代解决scheme(适用于iOS)

我正在使用具有Json结构的Firebase数据库来pipe理用户的评论。 { "post-comments" : { "post-id-1" : { "comment-id-11" : { "author" : "user1", "text" : "Hello world", "uid" : "user-id-2" },…. } 我想拉所有评论,但不包括当前用户的评论。 在SQL中,这将被翻译成:从后注释select*其中id!=“user-id-2” 据我所知,Firebase数据库不提供基于值的存在排除节点的方法(即:user id!= …)。 因此,是否有其他解决scheme来解决这个问题。 可以通过更改数据库结构,也可以在数据加载完成后处理数据源。 对于后者,我使用了FirebaseTableViewDataSource。 有没有办法在查询后过滤数据? 非常感谢