Do not be afraid, subclassing UITableView is very simple. In xCode, just select a new file, select "Cocoa Touch Classes", "Objective-c class" and select "UITableView" from the "Subclass" drop-down list. xCode will add a subclass of UITableViewController complete with stubs to build.
I filled out a very simple example that retrieves table data from an array and is displayed from the delegate application. Since you suggested sending the reloadData message to a UITableView, refresh the displayed data.
As you probably learned, using InterfaceBuilder for this task is much more complicated than doing it programmatically.
Cheers niels
// // MyTableViewController.m // TableView // // Created by Niels Castle on 7/15/09. // Copyright 2009 Castle Andersen ApS. All rights reserved. // #import "MyTableViewController.h" @implementation MyTableViewController // Initializer do custom initialisation here - (id)initWithStyle:(UITableViewStyle)style { if (self = [super initWithStyle:style]) { // This is the source of my data. The simplest source possible, // an NSMutableArray, of name. This would be the data from your web site array = [[NSMutableArray alloc] initWithObjects:@"Niels", @"Camilla", @"William", nil]; } return self; } // How many section do we want in our table - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view // Simply the number of elements in our array of names - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Reuse cells static NSString *id = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Simplest possible cell - displaying a name from our name array [[cell textLabel] setText: [array objectAtIndex:[indexPath row]]]; return cell; } - (void)dealloc { [super dealloc]; [array release]; } @end // // TableViewAppDelegate.m // TableView // // Created by Niels Castle on 7/15/09. // Copyright Castle Andersen ApS 2009. All rights reserved. // #import "TableViewAppDelegate.h" #import "MyTableViewController.h" @implementation TableViewAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { MyTableViewController *twc = [[MyTableViewController alloc] initWithStyle: UITableViewStylePlain]; [window addSubview: [twc view]]; [window makeKeyAndVisible]; } - (void)dealloc { [window release]; [super dealloc]; } @end
source share