【发布时间】:2012-01-03 11:13:53
【问题描述】:
所以我有一个UITableView,我用来自.plist 的数据填充表格视图。这对我来说一直很好,直到今天,当我尝试做同样的事情时,我无法让 numberOfRowsInSection, 方法工作。这是我的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if...
else if (segmentOptions == exchange){
NSArray *array = [NSArray arrayWithArray:[exchangeDictionary objectForKey:[listOfExchanges objectAtIndex:section]]];
return [array count];
}
//Else
return contentArray.count;
}
所以在那个代码中,每次我运行它时,代码都会崩溃。但是,我使用基本相同的代码来设置 tableview 文本并且效果很好:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
if...
else if (segmentOptions == exchange) {
NSArray *array = [NSArray arrayWithArray:[exchangeDictionary objectForKey:[listOfExchanges objectAtIndex:indexPath.section]]];
cell.textLabel.text = [array objectAtIndex:indexPath.row];
}
return cell;
}
而且该代码运行良好,这就是我如此困惑的原因。当我将行数设置为返回特定数字并运行其余代码时,一切正常。所以我真的迷路了。提前致谢
更新
我尝试使用正确的 count 表示法 return [array count];,但仍然遇到相同的崩溃和相同的控制台输出。
【问题讨论】:
-
当它崩溃时你会得到什么?
-
为了向您提供解决方案,我们需要查看崩溃报告,或至少查看有关崩溃的更多信息。
-
这是控制台中唯一出现的内容:
warning: Frame pointer point back at the previous frame (gdb)- 但我认为这没有用 -
引用确切的消息。你怎么知道它“崩溃”了?
-
(我怀疑你的“数组”返回为零。)
标签: iphone ios xcode uitableview tableview