繁体   English   中英

我的UITableView的第一项不起作用

[英]my UITableView's first item doesn't work

我的程序遇到一些奇怪的问题! 我创建了一个嵌套的可变数组,它由4个可变数组组成,每个可变数组包含一个字符串和另外4个数组,每个数组又包含两个字符串。 这是我通过NSLog传递数组时收到的日志:

然后,我使用了3个tableview控制器以某种方式在这些数组中创建了导航,就像第一个tableview控制器一样,我根据选择了原始数组的哪个项来加载第二个tableview控制器,依此类推。

一切对所有数组都适用,除了第一个顶层(第一个包含

我使用objectAtIndex并具有tempProjectNumber,该属性保存第一个用于选择项目的tableview控制器的选定index.row。 但是,当我的第二个tableviewcontroller加载cell.textlabel.text时,我收到了sigbart错误:

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSArrayI isEqualToString:]:无法识别的选择器已发送到实例0x8987c80'

我设法找到了为cell.textlabel加载文本时尝试访问的项目的类,它说这是一个> __ NSCFConstantString。

这是完整的日志:

>2011-11-13 01:36:42.031 iCodeMobile[4763:15203] indexpath.row: 1 projectnumber:0 
>2011-11-13 01:36:42.032 iCodeMobile[4763:15203] array: __NSCFConstantString 
>2011-11-13 01:36:42.033 iCodeMobile[4763:15203] indexpath.row: 2 projectnumber:0 
>2011-11-13 01:36:42.033 iCodeMobile[4763:15203] array: __NSCFConstantString   
>2011-11-13 01:36:42.034 iCodeMobile[4763:15203] indexpath.row: 3 projectnumber:0 
>2011-11-13 01:36:42.035 iCodeMobile[4763:15203] array: __NSCFConstantString 
>2011-11-13 01:36:42.036 iCodeMobile[4763:15203] indexpath.row: 4 projectnumber:0 
>2011-11-13 01:36:42.036 iCodeMobile[4763:15203] array: __NSArrayI>

index path.row记录是第二个视图控制器的表的行,项目号是第二个最高级别的数组,其中第一个项目是testproject1。 和数组日志记录是我要访问的项目的类。 如您所见,最后一个是NSArrayI,但我没有使用类似的东西,正如您从前面的数组映射中可以看到的那样。

有趣的是,如果我使用调试模式并进入每一行,则在所有单元格行都加载了正确的文本之后,我会收到此错误:

[CALayer objectAtIndex:]:无法识别的选择器发送到实例0x7f51f40我不使用任何层,我什至不知道该怎么做!

请帮忙,因为我正在处理这个问题将近一个月。 我正在使用uipickerview,发生了相同的事情,相同的第一项问题和相同的SIGBART错误!

谢谢。

更新@Mundi:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault    reuseIdentifier:CellIdentifier] autorelease];
    }
    if (indexPath.row==0)
    {
        cell.textLabel.text = @"Please Select A folder";
    }else
    {
        NSLog(@"indexpath.row: %u projectnumber:%u",indexPath.row,shared.tempProjectNumber);
        id object = [[shared.fileNameContainer objectAtIndex:shared.tempProjectNumber]    objectAtIndex:indexPath.row];
        if ([object isKindOfClass:[NSString class]]){
            NSLog(@"String: %@",[[[shared.fileNameContainer    objectAtIndex:shared.tempProjectNumber] objectAtIndex:indexPath.row]objectAtIndex:0]);
        }
        else
        {

            NSLog(@"array: %@",[[[[shared.fileNameContainer objectAtIndex:shared.tempProjectNumber] objectAtIndex:indexPath.row]objectAtIndex:0]class]);
        }

    cell.textLabel.text = [[[shared.fileNameContainer objectAtIndex:shared.tempProjectNumber] objectAtIndex:indexPath.row]objectAtIndex:0];

    };

    return cell;
}

在这里,shared.tempProjectNumber是项目数组的记录索引(我的主数组中最高级别的数组,即shared.fileNameContainer)。 这是我早些时候为该帖子获得的记录,并且在加载了表格的所有项目之后,我认为这是导致问题的最后一个项目,我收到sigbart错误! 非常感谢Mundi

更新:我找到了解决我的问题的简便方法,因此没有太多需要做的事情了,但感谢有人对此事有所了解

问候

您是否知道在c和(大多数其他编程语言)数组中索引从0count-1 因此,数组索引应该从03 ,而不是14

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM