numberOfRowsInSection starts with last section

后端 未结 2 481
再見小時候
再見小時候 2021-01-16 17:52

actually I\'m have a very simple problem (that\'s for sure) I just can\'t find the root cause.

The problem is, that after calling the numberOfSectionsInTableView Met

2条回答
  •  别那么骄傲
    2021-01-16 18:48

    I haven't had my coffee yet but I don't see how this will even compile.

    This line:

    Char *charSpecial = (Char *)[charSpecial objectAtIndex:indexPath.row];
    

    should presumably be:

    Char *charSpecial = (Char *)[charsSpecial objectAtIndex:indexPath.row];
    

    Note the "s". You have the Char type "charSpecial" when you wanted the NSArray "charsSpecial". (These aren't good variable names because they're differentiated only by a single letter buried in the middle. I suggest changing "charsSpecial" to "charSpecials" or better yet "charSpecilsArray".)

    Not sure this is your error because it looks more like a posting typo. You seem to have the same problem here:

    if ([charSpecial count] > 0) {
    
      NSDictionary *charsSpecialDict = [NSDictionary dictionaryWithObject:scodesSpecial forKey:@"Chars"];
      [listOfItems addObject:scodesSpecialDict];
    }
    

    This

    When I call my App, the section title has been set correctly to "#" but the data shows all the "X" values.

    Suggest that somewhere you are swapping your ordinal (zero indexed) value with your cardinal (one indexed). You're correctly querying the section names with an ordinal value but you are fetching your rows with the cardinal. Since the cardinal value is alway one more than the ordinal, you get an out of bounds error.

    I think you should refractor you variable names and look at the code again.

提交回复
热议问题