【发布时间】:2010-10-27 14:24:38
【问题描述】:
我有一个从 NSManagedObjects 数组生成的表。 这工作正常,直到我尝试在表格顶部添加一个额外的单元格。
这是我目前正在尝试的:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int menuLength = [mainMenu count] + 1;
return menuLength;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Check for reusable cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"UITableViewCell"];
// If no reusable cell, create one
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: @"UITableViewCell"] autorelease];
}
// Set the text on the cell with the genus name that is at the nth index of generaList
if ([indexPath row] == 0) {
[[cell textLabel] setText: @"All"];
} else {
NSManagedObject *filter = [mainMenu objectAtIndex: [indexPath row]];
[[cell textLabel] setText: [filter valueForKey: @"filter_label"]];
}
return cell;
}
当我尝试滚动表格时,它会引发以下异常:
'NSRangeException',原因:'* -[_PFArray objectAtIndex:]: index (9) beyond bounds (9)'
任何帮助将不胜感激!
【问题讨论】:
-
顺便说一句,-tableView:numberOfRowsInSection: 返回 10。
标签: objective-c iphone uitableview cocoa-touch uikit