'-[__NSDictionaryI length]: unrecognized selector sent to instance' - trying to figure out why

前端 未结 4 1479
别跟我提以往
别跟我提以往 2021-01-13 08:08

I\'ve a UITableView with custom UILabel for title and one another to subtitle, in order to align the text to right.

My data come from web s

相关标签:
4条回答
  • 2021-01-13 08:47

    In your tableView:willDisplayCell:forRowAtIndexPath:,

    check this line,

    cell = [Netroads willDisplayFlatDesignCell:cell];
    

    something wrong with this method, [Netroads willDisplayFlatDesignCell];

    You are trying to get a length from a NSDictionary instead of NSArray. If you are loading data from a JSON webservice, probably you are parsing NSDictionary as an NSArray. Fix that method, then it won't crash.

    0 讨论(0)
  • 2021-01-13 08:49

    You are setting the cell's text property to a dictionary:

    cell.textLabel.text = dict[@"Title"];
    

    From your log of dict:

    Title =     {
        };
    

    and:

    detailTextLabel.text = dict[@"Text"];
    

    From your log of dict:

    Text =     {
        };
    

    It's not clear exactly what values should be used from dict, but it should not be those dictionaries.

    0 讨论(0)
  • 2021-01-13 08:52

    According to your log, you're try to access NSDictionary object as NSString. That's why it leads to above error.

    Problem should be here..

     NSString *imageUrl = dict[@"imageUrl"];
    

    If it's dictionary, it should be crash in this line..

    if (imageUrl.length > 0)
    
    0 讨论(0)
  • 2021-01-13 09:02

    Reason: NSDictionary doesn't have lengh method but NSString has

    Change this line

        if (imageUrl.length > 0)
        {
    

    To

        if ([imageUrl isKindOfClass:[NSString class]] && imageUrl.length > 0)
        {
    
    0 讨论(0)
提交回复
热议问题