Three20對TableViewController 實現了更好的封裝,使實現列表類的界面更加簡單。現在我們使用TTTableViewController實現簡單的設置界面。 新建一個工程,導入Three20庫。新建一個類SettingsViewController繼承於TTTableViewContoller,在 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil方法中對view進行初始化並設置table的數據,具體代碼: [cpp] - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization self.title = @"設置"; self.tableViewStyle = UITableViewStyleGrouped; TTTableButton *userButton = [[TTTableButton alloc] init]; userButton.text = @"注銷 cloay"; userButton.delegate = self; userButton.selector = @selector(actionLoginOut); self.dataSource = [TTSectionedDataSource dataSourceWithObjects:@"賬號設置", userButton, @"網絡設置", [TTTableControlItem itemWithCaption:@"只在wifi網絡下加載圖片" control:[[UISwitch alloc] init]], @"評價打分", [TTTableButton itemWithText:@"給我們打分,評價一把" delegate:self selector:@selector(pingjia)], [TTTableButton itemWithText:@"意見反饋" delegate:self selector:@selector(feedback)], nil]; } return self; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization self.title = @"設置"; self.tableViewStyle = UITableViewStyleGrouped; TTTableButton *userButton = [[TTTableButton alloc] init]; userButton.text = @"注銷 cloay"; userButton.delegate = self; userButton.selector = @selector(actionLoginOut); self.dataSource = [TTSectionedDataSource dataSourceWithObjects:@"賬號設置", userButton, @"網絡設置", [TTTableControlItem itemWithCaption:@"只在wifi網絡下加載圖片" control:[[UISwitch alloc] init]], @"評價打分", [TTTableButton itemWithText:@"給我們打分,評價一把" delegate:self selector:@selector(pingjia)], [TTTableButton itemWithText:@"意見反饋" delegate:self selector:@selector(feedback)], nil];www.2cto.com } return self; } 大部分屬性與TableViewController一樣,Three20裡封裝了一些table UI控件,如按鈕等,可以直接充當cell。 效果圖: