Objective-c – How to display the UITableView programmatically

iphoneobjective cuitableview

I want to ask a question about the UITableView of the objective C. I am writing a program and I would like to create the UI programmatically. However, I don't know how to display the table programmatically. I already have a NSMutableArray to store the displayed data. And I create a object UITableView *tableData;, what should I do for the next step? Thank you very much.

Best Answer

Something like this should do the trick (assuming this is running from within your view controller and you have a property set up for the table view):

tableView = [[[UITableView alloc] initWithFrame:CGRectMake(...) style:UITableViewStylePlain] autorelease];
tableView.dataSource = self;
tableView.delegate = self;

[self.view addSubview:tableView];

Where you replace CGRectMake(...) with whatever position / size you'd like.