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

loon3y

macrumors 65816
Original poster
Oct 21, 2011
1,235
126
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.
 
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.
 
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.



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?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.