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

webznz

macrumors member
Original poster
Mar 8, 2011
82
0
Hobbitin
Hi, Im currently making an application that will at the end will use several different views to display information.

I am using a UITabBarController that I have defined in my appDelegate header file which is used to switch between a couple of main views. I also have a navigation bar on each view that can have buttons added to them like "edit" "add" etc, I am using these buttons to load "sub views" of the current main view and also loading the main views when user is in a subview.
(hope this makes sense.)

I am loading my sub views with the Add button that is connected to a method that looks like this.

Code:
- (IBAction)addSearch:(id)sender {
	NSLog(@"addSearch Button has been pressed for new search");
	
	//Load Query view
	Query *newQuery = [[Query alloc] initWithNibName:@"Query" bundle:nil];
	[self presentModalViewController:newQuery animated:YES];
	[newQuery release];
	
}

that opens the Query view that the user used to make their search query.
Where I get lost is that I have a back button where I want the user to be able to get back to the MainWindow.xib that has the UITabBarController on it etc. But I have no idea how to do it, any help would be appreciated.
 
Last edited:
:p I have seen
[self dismissModalViewControllerAnimated:YES];
I'm not sure how to implement it in this case?

I have a cancel button in my navigation bar of my subview and want to get back to my mainwindow where would I write this line? In a method in my subview.m file or am I completely off?
 
I have a cancel button in my navigation bar of my subview and want to get back to my mainwindow where would I write this line? In a method in my subview.m file or am I completely off?
Do you have your cancel button calling any methods now? Are you comfortable with the concept of connecting an event of a button with a method (usually known as an IBAction) in the view controller?
 
Arrr I found a solution :) with your help of course! got me searching for the right function.

I implemented an IBAction called cancelQuery in the subview that is connected to my cancel button in the navigation menu and its just one line of code :)

Code:
//Load new view
- (IBAction)cancelButton:(id)sender {
	NSLog(@"Query cancle button has been pressed");
	
	//Load/ Go back to MainWindow
[B]	[[self parentViewController] dismissModalViewControllerAnimated:YES];[/B]
	
}

thanks for the help :) I'm still new its just getting used to all the functions that are available to use aye.
 
And, just to be clear, your IBAction from that code is called cancelButton: and not cancelQuery. Accuracy is important in programming. You could've easily had another method called cancelQuery and possibly hooked up your button to the wrong method. So, pay attention to these details. Otherwise, they can easily trip you up.

Glad to hear you got it solved though. Time for a Resolved prefix on this thread? ;)
 
Oh god, newbiee situation here... where do I find the solved prefix..? :(

And yes thanks for the reminder, I'm terrible with that stuff... I have been working so hard at documenting my code I need to do better at being more accurate in my naming conventions etc.

Also One last question, I have several UITextFields that take input, when the cancel button is pressed would it be a good idea to clear the TextFields or release them or is it fine just to have the [UITextFieldname release]; in the dealloc method?

EDIT:

FOUND IT! lol saw your stick post, thanks again.
 
Last edited by a moderator:
Also One last question, I have several UITextFields that take input, when the cancel button is pressed would it be a good idea to clear the TextFields or release them or is it fine just to have the [UITextFieldname release]; in the dealloc method?
No need to clear them; releasing them in the dealloc is sufficient if they are properties.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.