开发者

iPhone custom UITableviewcontroller initialization problem

开发者 https://www.devze.com 2023-03-20 17:50 出处:网络
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?

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:multiSelectionViewCont开发者_JAVA百科roller 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;
}


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;


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消