通过UINavigationController将int变量传递给UITableView [英] pass int variable to UITableView Through UINavigationController

查看:112
本文介绍了通过UINavigationController将int变量传递给UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过UINavigationController将int变量传递给UITableView(我正在使用xcode 4.3)所以我创建了2个类(PartsTableViewController即UITableViewController和PartsNavController,即UINavigationController),我想传递变量从我当前的类到PartsTableViewController,然后用包含标题栏的导航控制器打开该表,所以我在当前类中写了以下代码:

I'm trying to pass int variable to UITableView through UINavigationController (I'm using xcode 4.3) So I created 2 classes (PartsTableViewController that is "UITableViewController" and PartsNavController that is "UINavigationController"), I want to pass the variable from my current class to PartsTableViewController and then open that table with its Navigation controller that contains the title bar , so I wrote in my current class the following code:

PartsNavController *partsNav = [self.storyboard instantiateViewControllerWithIdentifier:@"partsNav"];  
partsNav.groupId = myGroupp.bg_id;
[self presentModalViewController:partsNav animated:YES];

以及我在viewDidLoad中编写的PartsNavController类:

and in the PartsNavController class I wrote in viewDidLoad:

PartsTableViewController *parts = [self.storyboard instantiateViewControllerWithIdentifier:@"Parts"];
parts.groupId = groupId;
[parts.tableView reloadData];

以及我在viewDidLoad中写的PartsTableViewController:

and in PartsTableViewController I wrote in viewDidLoad:

NSLog(@"This is group: %d", groupId);

但运行时会产生2次输出,

but when run, it generates the output 2 times,

This is group:1
This is group:0

第一次是我发送的值,第二次是0,我只想要我发送的值,而不是0
我怎么能防止这个,只得到我的价值已发送????

first time is the value that I sent and the second time it outs 0 , I just want the value that I sent, not 0 how can I prevent this and get just the value that I sent ????

我想从(MaktabatyTableViewController)传递到(PartsTableViewController)而不使用segue

I want to pass from (MaktabatyTableViewController) to (PartsTableViewController) without using segue

推荐答案

更好的方法是在现有的UINavigationController中推送第二个TableViewController。最简单的方法是在StoryBoard中创建NavContr而不是TableViews,并将其单元与带有segue的前导视图控制器连接。而不是使用下面的方法:

The better way to do what you want is to push second TableViewController in existing UINavigationController. The easiest way to do that is to create that NavContr in StoryBoard and than to TableViews and connect it's cell with leading view controller with segue. And than use method below:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIViewController *destViewController = segue.destinationViewController;
    destViewController.integerValue = value;
}

这篇关于通过UINavigationController将int变量传递给UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆