UITableView - Нажмите View, нажав на ячейку - PullRequest
0 голосов
/ 09 марта 2011

Я создал UITableView с некоторыми ячейками (загруженными из массива), когда я щелкаю по ячейке, следующий код выдвигает имя с ячейкой, по которой щелкнули. Есть ли какой-нибудь более простой способ сделать это? Может быть, из цикла while?

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 Ответ

1 голос
/ 09 марта 2011
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];
...