Here's a tutorial on hooking up an array to a table view. I used it as a basis for learning and found it very helpful:
iPhone Programming Tutorial - Populating UITableView With An NSArray | iCodeBlog
I'm not aware offhand of being able to just programmatically say something like:
UITableView *x = [[UITableView alloc] init];
[x setData:myArrayData];
In a nutshell, create a new class that derives from UITableViewController. There are a couple of important methods : numberOfRowsInSection and cellForRowAtIndexPath.
numberOfRowsInSection needs to have a number returned to tell how many rows there are. This would typically be the number of items in your array. That array could be internal or inside your delegate. Here's an example of using the count from a data array inside the delegate:
Code:
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
return [delgate.myDataArray count];
}
The other one is what actually requests ( on a cell by cell basis ) the data that should go in that cell. Using the same example of having a data array inside your delegate, it would look something like this:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// lines for setting up the cell resource itself
// ....
// now set the cell data
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[cell setText:[delegate.myDataArray objectAtIndex:indexPath.row]];
return cell;
}
Hopefully that helps!