Search code examples
objective-ccocoa-touchnsarrayuitableview

objective-c init UITableViewController with data array?


I have four buttons, which have to push the same uiTableViewController, with different data in every case. I think I need to implement an initializer for my table and pass a NSArray. and then I'll check which button is pushed with the sender property.

Is that ok? How can I implement this initializer? I searched in the doc but I haven't get solution yet.


Solution

  • in your view controller you can initialize tableview by [UITableView alloc] initWithFrame:self.view.bounds]; and put this initialization in viewdidload method of your view controller,you don't need xib now. to be specific use

        [self.tableView = [UITableView alloc] initWithFrame:self.view.bounds];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.tableView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.000];
        self.tableView.bounces=YES;
        [self.view addSubview:self.tableView];
    
        self.tableView.delegate = self;
        self.tableView.dataSource = self;