Whats Wrong With My Code? (Presenting Modal View)

Discussion in 'iOS Programming' started by loon3y, Jun 12, 2012.

  1. loon3y macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #1
    I'm trying to have a modal view controller that i call programmatically.


    heres my code:



    Code:
    - (IBAction)searchView:(id)sender
    {
        GlobalStrings* theDataObject = [self theGlobalClass];
      
        if (theDataObject.presentSearch == nil)
        {  
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SearchBarViewController"];
            [vc setModalPresentationStyle:UIModalPresentationFullScreen];
          
            [self presentModalViewController:vc animated:YES];
        }
      
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SearchBarViewController"];
        [vc setModalPresentationStyle:UIModalPresentationFullScreen];
    }
    

    i get a sigbart error, is it because the view controller I'm calling is a navigation controller?


    i also have a similar method in my "ViewWillAppear" for my log in screen.
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    First, what does the first line return. If this object is a singleton, then use the class name, not self.

    Your code doesn't make sense in a simple way. You do a test and if it passes you setup a view controller and display it. Then after that you always try to set up another version of that view controller. I have to assume this code is a fake, a hack for this post, or just not well thought out.

    I'm not familiar with storyboards, but when you create an app and choose storyboarding, isn't the main storyboard named MainStoryboard by default, so it will be loaded upon app startup?

    So if I'm right about the MainStoryboard already existing and this code is within a view controller within that story board, then you should just use the 'storyboard' method against self to get the id. What you are trying to do is create a new copy. I have to wonder if creating vc from a new copy of the MainStoryboard and using it in the current copy has consequences.

    The docs say about instantiateViewControllerWithIdentifier: "Before you can use this method to retrieve a view controller, you must explicitly tag it with an appropriate identifier string in Interface Builder." The _it_ being the view controller.

    By the way, that presentModelViewController has been deprecated. Read the docs to see the replacement. I don't think that is an issue at this time.
     
  3. loon3y, Jun 14, 2012
    Last edited: Jun 14, 2012

    loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #3


    yea i just realized once i flag it, i won't be able to call it again till i exit/terminate the app

    I'm initially trying to make a lil search engine for this guys database through web service.


    the textfield is where the model number of the item (thats in the data base) is either typed in or scanned in (by linea pro sleeve)

    so its an essential part of my app, so basically i wanted to modally call a tableview from the textfield and than when u search it'll show a list of search results, and whatever u select will push the model number to the textfield in the "root view controller" that'll send the model number to the web service and return data.


    and if there is only one result, push it automatically to the textfield (in the root view) and automatically exit the searchtableview


    is there a better way?
     

Share This Page