[英]navigational controller not passing data from tableview to viewcontroller
The code for Tableview : Tableview的代码:
-(void)tableView:(UITableView *)tableView didselectRowAtIndexPath:(NSIndexPath *)indexPath{
ViewControllerDisplayMsg *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"viewController3"];
cellvalue=[array objectAtIndex:indexPath.row];
detail.DisplayMsgString = cellvalue;
[self.navigationController pushViewController:detail animated:YES];
}
Code in viewController3 : viewController3中的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.DisplayMsgLabel.text= self.DisplayMsgString;
}
The code above is not passing data its blank when the viewcontroller3 is opened.Why is the data not passing .What code is missing ? 上面的代码在打开viewcontroller3时没有传递数据为空白,为什么没有传递数据?缺少什么代码?
Please help me out.Really appreciate the help. 请帮帮我。非常感谢您的帮助。
Thanks in Advance. 提前致谢。
You have used 你用过
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
}
It is 它是
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
I hope you have typed it by mistake please share your result if it is something else than this 希望您输入的内容有误,如果不是此内容,请分享您的结果
Since I had segue from the story board The didselect method was not being called so - 由于我是从故事板上讲过的,所以没有调用didselect方法-
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// test segue.identifier if needed
ViewControllerDisplayMsg *viewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// set properties of viewController based on selection indexPath
cellvalue=[array objectAtIndex:indexPath.row];
NSLog(@"str : %@",cellvalue);
viewController.DisplayMsgtext = cellvalue;
} }
This worked perfectly fine.I have to check it if this is right way of implementing but otherwise its working fine now. 这工作得很好,我必须检查它是否是正确的实现方式,否则现在可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.