可可触摸表数据源的问题
-
22-08-2019 - |
题
我有一些麻烦从一个数据源显示结果。此代码将显示出不同的(和正确的)结果在控制台中,但会导致各种随机掷骰子的在模拟器。
( “结果” 是一个NSMutableArray属性的类。)
-(void) handleSearchForKeywords: (NSString *) keywords {
[results removeAllObjects];
int r = rand() % 10;
for( int i = 0; i < r; i++ ) {
[results addObject:[NSString stringWithFormat:@"test %i: %@", i, keywords]];
}
[self reloadTheTable];
}
-(void) reloadTheTable {
NSLog( @"current array contents: %@", results );
[tableView reloadData];
}
我猜测,这可能是与该阵列的记忆保持,或数组中的字符串?恐怕我还没有得到的是挂起。
[编辑回应马克贝西 - 我想,这里的一切是你的基本数据源的方法]
-(NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section {
return [results count];
}
-(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
static NSString *SearchViewControllerCell = @"SearchViewControllerCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SearchViewControllerCell];
if( cell == nil ) {
cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: SearchViewControllerCell] autorelease];
NSUInteger row = [indexPath row];
[cell setText:[results objectAtIndex:row]];
}
return cell;
}
解决方案
我不认为这个问题是在你已经发布的代码。它更可能在实现你的表视图的数据源代码。
不隶属于 StackOverflow