2011-03-09 64 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]; 
相关问题