Spring
Spring

Reputation: 11835

iPhone custom UITableviewcontroller initialization problem

The items array in my uitableview custom controller never gets filled from tmp array! debug hits the init method but nothing changed in self.items array?

in rootcontroller:

MultiSelectionTableViewController *multiSelectionViewController = [[MultiSelectionTableViewController alloc] initWithNibName:@"MultiSelectionTableViewController" bundle:nil];

[self.navigationController pushViewController:multiSelectionViewController animated:YES];       
[multiSelectionViewController release];

in MultiSelectionTableViewController

@property(nonatomic,retain) NSMutableArray *items;
@synthesize items;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {

    NSArray *tmp;
    tmp = [NSArray arrayWithObjects: @"Yes", @"No", @"Why not?", @"Depends..", nil];

    [self.items addObjectsFromArray:tmp];

 }
return self;
}

Upvotes: 0

Views: 257

Answers (2)

user756245
user756245

Reputation:

You have to alloc/init your array in the custom VC.

Do :

self.items = [NSArray arrayWithObjects: @"Yes", @"No", @"Why not?", @"Depends..", nil];

instead.

Or,

NSArray *tmp;
tmp = [NSArray arrayWithObjects: @"Yes", @"No", @"Why not?", @"Depends..", nil];
self.items = tmp;

Upvotes: 2

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

self.items is nil as it isn't allocated and initialized so its not filled or added to. You should do

self.items = tmp;

or directly

self.items = [NSArray arrayWithObjects: @"Yes", @"No", @"Why not?", @"Depends..", nil];

Upvotes: 1

Related Questions