Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

allian

macrumors newbie
Original poster
Apr 14, 2009
3
0
Hello everyone, (sorry for my english first)

I'll explain you my problem.
I have a UIViewController (TagCloudNavigationController) with a lot of UIViewController (MyTag) instance inside. Each instance is like an icon with an UIImageView and a UILabel. My desire is to push a new UIViewController when a user touch one of these icons.

I have a method called switchViews which works perfect if I call them from a button placed in my parent view (TagCloudNavigationController).

Code:
- (IBAction)switchViews:(id)sender {
	
	// Navigation logic may go here. Create and push another view controller.
	NavigationViewController *newViewController = [[NavigationViewController alloc] init];
	newViewController.tagTitle = @"Surf";
	[self.navigationController pushViewController:newViewController animated:YES];
	
}

But when I call this method from the touchesBegan :

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touch = [touches anyObject];
    if (touch.phase == UITouchPhaseBegan)
    {
	
		
		TagCloudNavigationController *huh = [[TagCloudNavigationController alloc] init];
		[huh switchViews:self.view.window];
		
    }    
}

it doesn't work !! the switchiews method is called (i see the nslog inside) but nothing happened.
I think the mistake comes from the calling of the switchViews.

Anyone can help me please.
Thanks
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Don't create a new TagCloudNavigationController to call switchviews on. Call switchviews on your already existing instance of TagCloudNavigationController.

What is the value of self.navigationController in the new instance of TagCloudNavigationController when you call switchviews? Probably nil since it hasn't been pushed itself.
 

allian

macrumors newbie
Original poster
Apr 14, 2009
3
0
yes it's exactly this !! the return value is nil !!

how I have to do to deal with my existing instance of TagCloudNavigationController, I don't know that.

Thank you
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Does your app delegate create the TagCloudNavigationController? If so keep this controller in an ivar and add a property to access it. In your touchesBegan that you showed read the property and then call switchviews with the single instance of the TagCloudNavigationController that you have.
 

allian

macrumors newbie
Original poster
Apr 14, 2009
3
0
thank for your answer, I don't know what is an ivar and I don't find anything clear on the net, but I've resolved my problem declaring a property in my class MyTag which is a UINavigationController. So when I create each instance of this class I fill this property with super.navigationController which is my rootLevel controller.


Now it works but I don't think it's the better way
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.