【发布时间】:2015-06-16 06:59:21
【问题描述】:
我想用户点击表格行,然后用户将转到其他页面。该页面具有情节提要 ID“其他视图”和恢复 ID“其他视图”。 但我不能去有目的的看法
这是我的代码:
- (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 方法,但它不起作用:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *otherViewCon;
otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:@"Other View"];
[self.navigationController pushViewController:otherViewCon animated:YES];
}
【问题讨论】:
-
显示 didSelectRowAtInedxPath 方法的代码
-
不,我没用过那个方法。我先试试……
-
你为什么不试试我在我的回答中写的:
[self performSegueWithIdentifier:@"ShowDetail" sender:tableView];你不需要创建一个新的 UIViewController -
请阅读 tableview 委托方法,以便您了解哪种方法有用。
-
@andika_kurniawan,你检查过,你的
didSelectRowAtIndexPath被调用了吗?
标签: ios objective-c tablerow