UITableView NSMutableArray和NSDictionary

UITableView NSMutableArray和NSDictionary,uitableview,nsmutablearray,nsdictionary,Uitableview,Nsmutablearray,Nsdictionary,从nsmutablearray填充tableview时出现此错误 数组被添加到字典中,字典被添加到可变数组中,但每次加载视图时,应用程序都会崩溃: [\uu NSArrayI isEqualToString:]:发送到实例的选择器无法识别 0x8a87e60 2014-05-24 12:23:02.589 jwStudy[77652:907]*终止 应用程序由于未捕获异常“NSInvalidArgumentException”,原因: '-[[uuuu NSArrayI isEqualToStr

从nsmutablearray填充tableview时出现此错误

数组被添加到字典中,字典被添加到可变数组中,但每次加载视图时,应用程序都会崩溃:

[\uu NSArrayI isEqualToString:]:发送到实例的选择器无法识别 0x8a87e60 2014-05-24 12:23:02.589 jwStudy[77652:907]*终止 应用程序由于未捕获异常“NSInvalidArgumentException”,原因: '-[[uuuu NSArrayI isEqualToString:]:无法识别的选择器发送到 实例0x8a87e60'

日志输出确认数组和键已正确添加。 但是为什么cellForRowAtIndexPath:方法中的单元格会抛出错误? 代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];


    languageArray = [[NSMutableArray alloc] init];
    languages = [[NSArray alloc] initWithObjects:@"Abbey", @"Abkhasisk", @"Abua", nil];

    downloadURL = [[NSArray alloc] initWithObjects:@"http://download.jw.org/files/content_assets/bb/502013341_ABB_cnt_1_r480P.mp4",
                   @"http://download.jw.org/files/content_assets/3c/502013341_ABK_cnt_1_r480P.mp4",
                   @"http://download.jw.org/files/content_assets/7e/502013341_AU_cnt_1_r720P.mp4", nil];

    mutedict = [NSDictionary dictionaryWithObjectsAndKeys:languages, @"FirstKey", downloadURL, @"SecondKey", nil];
    [languageArray addObject:mutedict];

   NSLog(@"%@",languageArray);

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

        return languageArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *simpleTableIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    // ERROR HERE!!!
    cell.textLabel.text =  [[languageArray objectAtIndex:indexPath.row] objectForKey:@"FirstKey”];

    if ([checkCellLanguage isEqual:indexPath]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

在代码中,两个数组存储在一个字典中,字典存储在一个数组中

像这样:

languageArray ----- mutedict ------ languages (FirstKey)

                       |
                       |
                        ----------- downloadURL(SecondKey)
cell.textlab.text
是一个
NSString
,但是
[[languageArray objectAtIndex:indexath.row]objectForKey:@“FirstKey”];
NSArray

所以你的代码会抛出一个错误

如果您想将
语言
作为
单元格.textlab.text

您可以将代码修改为
cell.textlab.text=[[mutedict objectForKey:@“FirstKey”]objectAtIndex:indexath.row]

希望它能帮助你:)

@Farhan和Joy

谢谢你们两位的及时回复。我现在意识到我的问题还不够清楚。我想让tableview中的每一行注册该行对应的URL。所以我最终放弃了数组和字典…太混乱了。改为使用2个NSArray。这个链接让我走上了正确的轨道,并且现在一切正常:


您的checkCellLanguage类型是NSInteger吗?此外,objectForKey方法只能在NSDictionary实例上调用。您应该将数组对象存储到dictionary中,而不是dictionary存储到数组中。之后,您可以在NSDictionary对象上使用objectForKey。您可以忽略checkCellLanguage变量。这仅用于add正在为所选行设置复选标记。对于如何正确存储数组对象,我感到有点困惑。您能详细说明一下吗?当然可以。您的arrayLanguage变量自分配(整*mutedict)以来就超出了范围索引0处只有一个对象。您可以使用for循环来分配字典,其中循环的限制可以是您要分配的数组的大小。您可以看到这一点。这会有所帮助。谢谢Farhan。我将查看它。