Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

iphone - pass int variable to UITableView Through UINavigationController

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];

and in the PartsNavController class I wrote in viewDidLoad:

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

and in PartsTableViewController I wrote in viewDidLoad:

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

but when run, it generates the output 2 times,

This is group:1
This is group: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 ????

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...