Resolved Navigational question

Discussion in 'iOS Programming' started by webznz, Mar 24, 2011.

  1. webznz, Mar 24, 2011
    Last edited: Mar 24, 2011

    webznz macrumors member

    Joined:
    Mar 8, 2011
    Location:
    Hobbitin
    #1
    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.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You mean something along the lines of dismissing your modal view controller? (Hint, hint).
     
  3. webznz thread starter macrumors member

    Joined:
    Mar 8, 2011
    Location:
    Hobbitin
    #3
    :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?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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?
     
  5. webznz thread starter macrumors member

    Joined:
    Mar 8, 2011
    Location:
    Hobbitin
    #5
    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.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    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? ;)
     
  7. webznz, Mar 24, 2011
    Last edited by a moderator: Mar 25, 2011

    webznz thread starter macrumors member

    Joined:
    Mar 8, 2011
    Location:
    Hobbitin
    #7
    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.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    No need to clear them; releasing them in the dealloc is sufficient if they are properties.
     

Share This Page