2011-03-09 30 views
0

我已經創建了一些單元格(從數組加載)的UITableView,當我單擊單元格時,下面的代碼將單擊的單元格的名稱推入。有沒有更簡單的方法來做到這一點?也許從一段時間內循環?UITableView - 通過單擊單元格推視圖

if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:@"Schulsekretariat"]){ 
    Schulsekretariat *schulsekretariat = [[Schulsekretariat alloc] initWithNibName:@"Schulsekretariat" bundle:nil]; 
    [self.navigationController pushViewController:schulsekretariat animated:YES]; 
    [schulsekretariat release]; 
} 


else if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:@"Zivilstandesamt"]){ 
    Zivilstandesamt *zivilstandesamt = [[Zivilstandesamt alloc] initWithNibName:@"Zivilstandesamt" bundle:nil]; 
    [self.navigationController pushViewController:zivilstandesamt animated:YES]; 
    [zivilstandesamt release]; 
} 

else if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:@"Feuerwehr"]){ 
    Feuerwehr *feuerwehr = [[Feuerwehr alloc] initWithNibName:@"Feuerwehr" bundle:nil]; 
    [self.navigationController pushViewController:feuerwehr animated:YES]; 
    [feuerwehr release]; 
} 

回答

1
NSString *name = [arrayWeitere objectAtIndex:indexPath.row]; 
Class *myClass = [Class classNamed:name]; 

myClass *vc = [[myClass alloc] initWithNibName:name bundle:nil]; 
if (vc != nil) { 
    [self.navigationController pushViewController:vc animated:YES]; 
} 
[vc release]; 
相關問題