【发布时间】:2011-08-23 16:10:52
【问题描述】:
我想在我的 Stages dict 中读取我的数组并将其显示到 tableview 中。但是,我的应用程序崩溃并给出错误消息:* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x4b43ee0'
我能够在 Stages 字典中显示数组的行数,但无法在表格单元格中显示名称。
下面是我的 plist 和代码。
根(数组)
Item 0 (Dict) Project Name (String) Stage (Dict) Analysis (Array) Design (Array) Develop (Array) Implement (Array)
在我的 viewDiDLoad 方法中,我调用了
//course is a nsdictionary which is pass down from the previous view
stages = [course objectForKey:@"Stage"];
表格视图方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger rows = 0;
if (section == 0){
rows = 1;
}
if (section == 1) {
return [stages count];
}
return rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"StagesCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
}
// Set up the cell
if (indexPath.section == 0) {
if (indexPath.row == 0) {
cell.textLabel.text = @"Project Name";
cell.detailTextLabel.text = [course objectForKey:@"ProjectName"];;
}
}
if (indexPath.section == 1) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSString *cellvalue = [stages objectAtIndex:indexPath.row];
cell.textLabel.text = cellvalue;
}
return cell;
}
提前致谢(:
【问题讨论】:
标签: iphone objective-c ios uitableview plist