and*_*wan 3 objective-c tablerow ios
我想用户点击表格行然后用户将转到其他页面.该页面具有故事板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;
}
Run Code Online (Sandbox Code Playgroud)
此代码不起作用:
UIViewController *otherViewCon;
otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:@"Other View"];
[self.navigationController pushViewController:otherViewCon animated:YES];
Run Code Online (Sandbox Code Playgroud)
更新 我已插入新代码.我使用didSelectRowAtIndexPath方法,但它不起作用:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *otherViewCon;
otherViewCon = [self.storyboard instantiateViewControllerWithIdentifier:@"Other View"];
[self.navigationController pushViewController:otherViewCon animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
试试这个方法 didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"ShowDetail" sender:tableView];
}
Run Code Online (Sandbox Code Playgroud)
如果要在变量发送之前传递变量或执行操作,请执行以下操作:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ShowDetail"]) {
//Do something
Detail *detailController = (Detail*)segue.destinationViewController;
}
}
Run Code Online (Sandbox Code Playgroud)
如果你想知道如何命名segue,这里有一个很棒的教程来自apple docs:Naming Segues
| 归档时间: |
|
| 查看次数: |
14066 次 |
| 最近记录: |