【发布时间】:2016-02-18 05:51:37
【问题描述】:
这是我的 NSMutableArray:
tableviewarray=[NSMutableArray arrayWithObjects:@"ca1.png", @"ca2.png", @"ca3.png", @"ca4.png", @"ca5.png", @"ca6.png", @"ca7.png", @"ca8.png",@"ca9.png",@"ca10.png",nil];
NSLog(@"loaded into array =%@",tableviewarray);
loaded into array =(
"ca1.png",
"ca2.png",
"ca3.png",
"ca4.png",
"ca5.png",
"ca6.png",
"ca7.png",
"ca8.png",
"ca9.png",
"ca10.png"
)
我打印了我的数组,所有东西都正确添加了
当我尝试在 tableview 中使用这个数组时,我得到了错误:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"reload+option=%@",tableviewarray);
TableViewCell *cell;
cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.images.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[tableviewarray objectAtIndex:indexPath.row]]];
return cell;
}
错误:
reload+option={( -[__NSSetM objectAtIndex:]: 无法识别的选择器 发送到实例 0x146c05c0 * 由于未捕获而终止应用程序 异常'NSInvalidArgumentException',原因:'-[__NSSetM objectAtIndex:]: 无法识别的选择器发送到实例 0x146c05c0' * 第一次抛出调用栈:(0x2115c10b 0x20902e17 0x21161925 0x2115f559 0x2108fc08 0xad8eb 0x255da6bd 0x255da7fd 0x255ca031 0x255defcb 0x2538285b 0x25294d13 0x23393f99 0x2338f695 0x2338f529 0x2338ea49 0x2338e6fb 0x23387ebb 0x2111ef59 0x2111d25d 0x2111d68f 0x21070bf9 0x210709e5 0x222bcac9 0x25300ba1 0x9687f 0x20d1f873) libc++abi.dylib:以未捕获的类型异常终止 NSException
NSMutableArray 初始化:
-(void)viewdidload
{
[super viewdidload];
tableviewarray=[[NSMutablearray alloc]init];
}
1:http://i.stack.imgur.com/ydFGE.png这里我把tableviewarray改成了arrimages
【问题讨论】:
-
该消息说
tableviewarray是一个NSMutableSet,而不是一个数组,所以它不理解objectAtIndex;仔细检查您修改tableviewarray的任何地方 -
只有当方法进入tableviewcellfor row at index path @Paulw11时才会出现这个问题
-
您在哪里设置阵列?你如何定义这个变量?当你使用这个方法时,它是一个 NSMutableSet
-
添加这个试试这个 if(!cell) { cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; }
-
这个程序使用 ARC 吗?如果不是,则该数组可能已被释放,并且恰好在同一位置分配了一个集合。
标签: ios objective-c uitableview nsmutablearray nsset