通过编程实现UINavigationController 包含 UITableViewController
#import "RootViewController.h"#import "SimpleTableViewAppDelegate.h"@implementation RootViewController@synthesize timeZoneNames;- (void)viewDidLoad { //设定当前控制器的标题,以备导航控制器显示 //通过第一个参数作为键取当前程序沙盒中找Localizable.strings文件中的内容,第二个参数是备注这个字段的意思,不显示到界面中的。self.title = NSLocalizedString(@"Time Zones", @"Time Zones title"); }//接口继承自UITableViewController,需要实现这个方法获得一共有多少部分。- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {// 这里只有一个部分.return 1;}//接口继承自UITableViewController,需要实现这个方法获得每一部分有多少行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {// Return the number of time zone names.return [timeZoneNames count];}//回调方法,表格视图控制器的每一行的显示都是通过这个方法进行处理的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {static NSString *MyIdentifier = @"MyIdentifier";// Try to retrieve from the table view a now-unused cell with the given identifier.UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];// If no cell is available, create a new one using the given identifier.if (cell == nil) {// Use the default cell style.cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];}// 从时区数组中获得当前行号对应的时区数据作为这行的文本显示NSString *timeZoneName = [timeZoneNames objectAtIndex:indexPath.row];cell.textLabel.text = timeZoneName;return cell;}/* To conform to Human Interface Guildelines, since selecting a row would have no effect (such as navigation), make sure that rows cannot be selected. 当对表格行进行选择时,禁止做选择动作。 */- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {return nil;}- (void)dealloc {[timeZoneNames release];[super dealloc];}@end