开发者

UITableView - Push a View by clicking on a cell

I have created an UITableView with some cells (loaded from an array), when I click on a cell the following code pushes the name with the clicked cell. Is there some easier way to do that? Maybe from within a while loop?

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 pushVie开发者_开发技巧wController:feuerwehr animated:YES];
    [feuerwehr release];
}


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜