简体   繁体   中英

my UITableView's first item doesn't work

I am having some weird problem with my program!! I have created a nested mutable array, which consists of 4mutable arrays, each containing a string and 4 other array, each again containing a two strings. here's the log I received when I passed my array through NSLog:

I have then used 3 tableview controllers to somehow create a navigation through these arrays, as with the first tableview controller, I load the second one depending on which item of the original array was selected, and so on and so forth.

everything works perfectly for all the arrays, except the first top level one (the first array containing

I use objectAtIndex and have tempProjectNumber, which holds the selected index.row of the first tableview controller for selecting the project. however, when my second tableviewcontroller loads the cell.textlabel.text, I receive a sigbart error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x8987c80'

I managed to find out the class of the item I try to access when loading the text for cell.textlabel, and it says it's a >__NSCFConstantString.

this is the complete log:

>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>

the index path.row recordings are the row of the table for second view controller, and the project number is the second highest level array, with first item of testproject1. and the array loggings are the class of the item I'm trying to access. as you can see the last one is the NSArrayI, but I'm not using anything like that, as you can see from the mapping of my array earlier.

interestingly, if I use debugging mode and step into each line, after all the cell rows have been loaded with the texts, which are correct, I get this error:

[CALayer objectAtIndex:]: unrecognized selector sent to instance 0x7f51f40 I'm not using any layers, and I don't even know what to do!!!

Please help as I'm dealing with this problem for almost a month. I was using uipickerview and the same thing happened, the same first item problem and the same SIGBART error!!!

Thanks.

UPDATE @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;
}

in here, shared.tempProjectNumber is the recorded index of the project array (highest level of arrays within my main array, which is shared.fileNameContainer). This is the recording I got for that post earlier, and after all the items of the table has been loaded, and I take it is the last item which causes the problem, I receive the sigbart error!! Thanks a lot Mundi

update: I have found an easier way to tackle my problem, so not much need of going further, but appreciate anyone shed some light on the matter

regards

Are you aware that in c and (most other programming languages) arrays are indexed from 0 to count-1 ? Thus your array indices should go from 0 to 3 , not from 1 to 4 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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