Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

NSArray *array = [[NSArray alloc] initWithObjects:@"ΕΛΤΑ",
                      @"ΕΛΤΑ COURIER", @"ACS", @"ACS ΕΞΩΤΕΡΙΚΟ", 
                      @"DHL", @"INTERATTICA", @"SPEEDEX", 
                      @"UPS", @"ΓΕΝΙΚΗ ΤΑΧΥΔΡΟΜΙΚΗ", @"ΜΕΤΑΦΟΡΙΚΕΣ ΕΞΩΤΕΡΙΚΟΥ", nil];

This is working because it has nil at the end.

But I add objects like this: addObject:name etc... So at the end I have to add nil I do this addObhect:nil but when I run the app it still crashes at cellForRowAtIndexPath:

how can I do this work?

Ok, I dont have to add nil

What is the reason that my app crashes then?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
537 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you must add a nil object to a collection, use the NSNull class:

The NSNull class defines a singleton object used to represent null values in collection objects (which don’t allow nil values).

Assuming "array" is of type NSMutableArray:

....
[array addObject:[NSNumber numberWithInt:2];
[array addObject:@"string"];
[array addObject:[NSNull null]];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...