2011-05-21 74 views
2


我的視圖是導航控制器內部的表格視圖。我用別人的代碼來做到這一點,而且我知道這是編寫代碼時人的意圖,但是當我觸摸表格單元格時,它給我帶來了相同的看法。你將如何批評下面的代碼來爲每個不同的表單元格加載不同的筆尖。簡單表格導航幫助

MoreTableViewController.h

@interface MoreTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> { 
IBOutlet UITableView *moreTableView; 
NSMutableArray *moreArray; 
AboutDetailViewController *aboutDetailViewController; 

} 

@property (nonatomic, retain) NSMutableArray *moreArray; 
@property (nonatomic, retain) AboutDetailViewController *aboutDetailViewController; 
@end 

MoreTableViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSInteger row = [indexPath row]; 
if (self.aboutDetailViewController == nil) { 
    AboutDetailViewController *aboutD = [[AboutDetailViewController alloc] initWithNibName:@"AboutDetailViewController" bundle:nil]; 
    self.aboutDetailViewController = aboutD; 
    [aboutD release]; 

} 
aboutDetailViewController.title = [NSString stringWithFormat:@"%@", [moreArray objectAtIndex:row]]; 

ROSS_APP_7AppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 
[delegate.moreNavController pushViewController:aboutDetailViewController animated:YES]; 

}

如果要我把if語句做的?如果是這樣,我將如何編寫代碼。我需要我能得到的所有幫助。 謝謝你的幫助。

回答

0
if(indexPath.row == 0) 
{ 
    AboutDetailViewController *aboutD = [[AboutDetailViewController alloc] initWithNibName:@"AboutDetailViewController" bundle:nil]; 
    self.aboutDetailViewController = aboutD; 
    [aboutD release]; 
} 
else if(indexPath.row == 1) 
{ 

} 
else if(indexPath.row == 2) 
{ 

} 

好吧....

而且你寫的這些東西在下面的方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
+0

太謝謝你了! – Sam

1
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSInteger row = [indexPath row]; 
     switch(row) { 
      case 0: 
      // First row 
      // Push xib 
      break; 

      case 1: 
      // Second row 
      // Push xib 
      break; 
     } 
}