开发者

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: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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜