目标 c - 单击表格行并转到另一页 [英] objective c - click table row and go to another page
问题描述
我想用户点击表格行,然后用户将转到其他页面.该页面具有 Storyboard IDOther View"和恢复 IDOther View".但我不能去有目的的视图
I want to user click table row then after it user will go to other page. The page has Storyboard ID "Other View" and Restoration ID "Other View". But I can't go to purposed view
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tabel cellForRowAtIndexPath:(NSIndexPath *)indeksBaris
{
static NSString *simpleTableIdentifier = @"TampilanCell";
TabelBeritaCell *cell = (TabelBeritaCell *)[tabel dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSLog(@"nilai : %d", indeksBaris.row );
//detecting NIB of table view
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableView" owner:self options:nil];
cell = [nib objectAtIndex:0];
//Go To View Controller which have identifier "Other View"
UIViewController *otherViewCon;
otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:@"Other View"];
[self.navigationController pushViewController:otherViewCon animated:YES];
cell.judulBerita.text = [listBerita objectAtIndex:indeksBaris.row];
return cell;
}
此代码不起作用:
UIViewController *otherViewCon;
otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:@"Other View"];
[self.navigationController pushViewController:otherViewCon animated:YES];
更新我已经插入新代码.我使用 didSelectRowAtIndexPath 方法,但它不起作用:
UPDATED I have insert new code. I use didSelectRowAtIndexPath method but it doesn't work :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *otherViewCon;
otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:@"Other View"];
[self.navigationController pushViewController:otherViewCon animated:YES];
}
推荐答案
试试didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"ShowDetail" sender:tableView];
}
如果你想传递一个变量或在它继续之前执行一个动作,请执行以下操作:
If you want to pass a variable or perform an action before it segues, do the following:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ShowDetail"]) {
//Do something
Detail *detailController = (Detail*)segue.destinationViewController;
}
}
如果你想知道如何命名转场,这里有一个来自苹果文档的很棒的教程:命名 Segue
If you want to know how to name a segue, here is a great tutorial from apple docs: Naming Segues
这篇关于目标 c - 单击表格行并转到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!