Vladimir
Vladimir

Reputation: 11

NULL elements in NSMutableArray

I have a problem... IN my MuttableArray have N element, but all elements is null

.h
        @interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> {
            NSMutableArray *listProjectPost;
        }

@property (retain,nonatomic) NSMutableArray *listProjectPost;

.m
@implementation ViewController
@synthesize  listProjectPost;

-(void)dealloc
{
    [self.listProjectPost release];
    [super dealloc];
}

-(void)viewWillAppear:(BOOL)animated{
    self.listProjectPost = [NSMutableArray array];

// loop code
// current element
            currentNews *dop = [[currentNews alloc] init];
            [self.listProjectPost addObject:[dop createElement:node]];
            [dop release];
}

in

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
currentNews *dop = [self.listProjectPost objectAtIndex:indexPath.row];
cell.textLabel.text = [dop getTitle];
...
}

all ok in top view (view when creating) but next index i have error - EXC_BAD_ACCESS

sorry for my english

Upvotes: 0

Views: 380

Answers (1)

Dylan Copeland
Dylan Copeland

Reputation: 1249

If you need to store a null value in an Objective-C array, use [NSNull null]. You should check [drop createElement:node] to see if it is nil before adding it to your array.

Upvotes: 1

Related Questions