当我使用表视图时,我的iphone应用程序崩溃
文件values.plist中插入了三个值,它们填充函数viewDidLoad()中的NSArray“table”,但我的应用程序在当我使用表视图时,我的iphone应用程序崩溃,iphone,xcode,Iphone,Xcode,文件values.plist中插入了三个值,它们填充函数viewDidLoad()中的NSArray“table”,但我的应用程序在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *theCell=[UITableViewCell alloc]; theCell=[theCell in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *theCell=[UITableViewCell alloc];
theCell=[theCell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSLog(@"%i",[table count]);
theCell.textLabel.text=[table objectAtIndex:[indexPath row]];
return theCell;
}
请注意以下问题: 1) 确保NSArray具有值,即它已填充 2) 还可以尝试
NSLog(@“%d”,[table count])代码>
我认为你最好选择%d
,而不是%I
希望这对您有所帮助。这是标准实现:
" theCell.textLabel.text=[table objectAtIndex:[indexPath row]]; "
But the line "NSLog(@"%i",[table count]);" works and shows me 3
please help .
作为旁注,这是ARC实现。如果您不使用ARC,只需添加自动释放:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [table objectAtIndex:indexPath.row];
return cell;
}
还要确保数据源numberOfSections设置正确:
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autoRelease];
并将numberOfRows设置为数组:
return 1;
发布应用程序崩溃时收到的错误消息会有所帮助。在控制台中查看以找到它。堆栈跟踪也很有用。那么错误消息是什么呢??确保数组中有字符串值。
return [table count];