我希望能夠在我的tableview中選擇一個項目,並獲得正確的視圖。 說我有兩個項目在我的uitableview。一個有Ubuntu的價值其他有一個拱門的價值 - 在我的plist從arraA我有一個SystemID的持有文本Ubuntu /拱,從來都沒有didSelectRowAtIndexPath或prepareForSegue使用?
現在當我選擇與Ubuntu的一個我希望它推動一個新的觀點,其中Ubuntu的東西是 ,如果我回去,並選擇拱它會再次推我到一個視圖,其中拱東西
到目前爲止,我做了這個,它不是如預期運行:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *segueName = nil;
if ([[arrayA valueForKey:@"SystemID"]isEqualToString:@"Ubuntu Linux"]) {
ActionViewController *controller = [[ActionViewController alloc] initWithNibName:@"Ubuntu Linux" bundle:nil];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
[self.navigationController pushViewController:controller animated:YES];
}
else if ([[arrayA valueForKey:@"SystemID"]isEqualToString:@"Arch Linux"]) {
ActionViewController *controller = [[ActionViewController alloc] initWithNibName:@"Arch Linux" bundle:nil];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
[self.navigationController pushViewController:controller animated:YES];
}
[self performSegueWithIdentifier: segueName sender: self];
}
也試過準備forsegue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([arrayA valueForKey:@"Arch Linux"])
{
ActionViewController *controller = (ActionViewController *)segue.destinationViewController;
NSIndexPath *indexPath = [self.mainTableView indexPathForSelectedRow];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
NSLog(@"hostname = %@", controller.Serverinfo);
}
if ([arrayA valueForKey:@"Ubuntu Linux"]) {
ActionViewController *controller = (ActionViewController *)segue.destinationViewController;
NSIndexPath *indexPath = [self.mainTableView indexPathForSelectedRow];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
NSLog(@"hostname = %@", controller.Serverinfo);
}
}
arrayA是NSMutableArray的是從plist中讀取,你可以在這裏看到
是一個數組NSAray或NSMutableArray的類型?你在arrayA中保存兩個NSString類型的對象嗎? – Greg
我想你需要在這段代碼中使用'indexPath'或'sender'來知道哪一行被選中。 –
arrayA是一個NSMutableArray。兩個具有不同值的對象 – KennyVB