How do I pass an NSString through 3 ViewControllers?
Posted
by dBloc
on Stack Overflow
See other posts from Stack Overflow
or by dBloc
Published on 2010-05-03T22:00:05Z
Indexed on
2010/05/03
22:08 UTC
Read the original article
Hit count: 229
hey, I'm currently using the iPhone SDK and I'm having trouble passing an NSString through 3 views
I am able to pass an NSString between 2 view controllers but I am unable to pass it through another one. My code is as follows...
`- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)index`Path {
NSString *string1 = nil;
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"items"];
string1 = [array objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
ViewController2 *vc2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]];
vc2.string1 = string1;
[self.navigationController pushViewController:vc2 animated:YES];
[vc2 release];
vc2 = nil;
}
in the "ViewController 2" implementations I am able use "string1" in the title bar by doing the following....
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = string1;
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"icon_time.png"]
style:UIBarButtonItemStylePlain
//style:UIBarButtonItemStyleBordered
target:self
action:@selector(goToThirdView)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
}
but I also have a NavBar Button on the right side that I would like to push a new view
- (void)goToThirdView
{
ViewController3 *vc3 = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:NESW animated:YES];
vc3.string1 = string1 ;
[vc3 release];
vc3 = nil;
}
How do I pass on that same string to the third view? (or fourth)
© Stack Overflow or respective owner