我想读取和显示我的数组在我的阶段,切入到表视图。但是,我的应用程序崩溃了,并给出了错误消息:*终止应用程序是由于非正常的异常'NSInvalidArgumentException',原因是:‘__NSCFDictionary::未识别的选择器发送到实例0x4b43ee0’
我能够在dict阶段中显示数组的行数,但不能在表单元格中显示名称。
下面是我的拼贴和密码。
根(阵列)
项目0 (Dict)项目名称(字符串)阶段(Dict)分析(数组)设计(数组)开发(数组)实现(数组)
在我的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;
}
预先谢谢(:
发布于 2011-08-22 23:43:01
stages
元素是字典,而不是数组。我猜字典中的每个元素都是数组对象,您希望在表视图中显示这些键。
此外,所给出的plist似乎与示例不匹配。在标签为“course”的字典中指定Stage
,但在plist中,它显示了Stages
也许你想试试:
stages = [[course objectAtIndex:@"Stages"] allKeys];
发布于 2011-08-22 23:38:47
在您的plist文件中,项目名称变量显示为:Project Name
,在此行:cell.detailTextLabel.text = [course objectForKey:@"ProjectName"];;
中,它显示为:ProjectName
。我觉得两者必须是一样的。也许这个只出现在这里。
出现错误是因为stages变量是字典,正如您在PList文件中可以看到的那样,但是您尝试将其用作数组。如我所见,阶段词典包含4个键:分析、设计、开发、设计(字典中的相同键??)。因此,您必须首先使用- (id)objectForKey:(id)aKey;
方法,其中一个键在阶段字典中,然后再使用objectAtIndex:
方法。
发布于 2011-08-23 00:10:52
NSString *cellvalue = [stages.allValues objectAtIndex:indexPath.row];
注意"allValues“。allValues返回字典中所有值的数组,allKeys返回字典中所有键的数组。
https://stackoverflow.com/questions/7157604
复制相似问题