0

I am using plist to save some data as follow, saving method

 NSMutableArray * highScores = [NSMutableArray arrayWithObjects:
                                       [NSNumber numberWithInt:597],
                                       [NSNumber numberWithInt:452],
                                       [NSNumber numberWithInt:365],
                                        nil];

        [defaults setObject:highScores forKey:@"high_scores"];

loading method

 NSMutableArray * highScores = [defaults objectForKey:@"high_scores"];

    for(NSNumber * score in highScores) {
        NSLog(@"Score: %i", [score intValue]);
        if (score >=100) {
            --> OPEN A SPECIFIC UIVIEWCONTROLLER ON THE STORYBOARD
            NSLog(@">100");

        }
    }

When i load the data say, if the score > 100 using the following code, i would like it to open a specific uiviewcontroller on my storyboard. May i know how can i do that?

Thanks

Clarence
  • 1,951
  • 2
  • 34
  • 49
  • Have a look at the chosen answer on here http://stackoverflow.com/questions/8348109/how-can-i-manually-switch-between-uiviewcontrollers-in-storyboard this should answer your question as it provides and answer on how to change view controllers programmatically using storyboards. As a side note I have voted to close as a duplicate question because this has been asked thousands of times, though I don't believe this deserves a downvote though. – Popeye Jul 23 '14 at 07:30
  • If you do use that link I would add a cast to it like `LoginViewController *controller = (LoginViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"LoginIdentifier"];` Here's another one http://stackoverflow.com/questions/10933939/how-to-switch-views-programmatically-in-a-viewcontroller-xcode-iphone – Popeye Jul 23 '14 at 07:33
  • use this link for particularly open the view controller http://stackoverflow.com/questions/23102978/swrevealviewcontroller-without-using-navigationcontroller/23105142#23105142 – Anbu.Karthik Jul 23 '14 at 07:47
  • @Anbu.Karthik I love how like the answers below you are using unnecessary memory to allocate a new instance of `UIStoryboard` when there should already be an instance created under `self.storyboard`, why are you allocating unnecessary memory to create a new instance of a storyboard? – Popeye Jul 23 '14 at 07:50
  • @Popeye - I below 1 yr exp in iOS, but I love my professional and job, I understand your question, how to optimize this – Anbu.Karthik Jul 23 '14 at 07:53
  • @Anbu.Karthik please note that it is still correct but really it should be `self.storyboard` for better memory management and what not especially since storyboards can be pretty big in memory. Good luck with future coding. – Popeye Jul 23 '14 at 08:23
  • @Popeye -- Tanx senior, onwards I follow this – Anbu.Karthik Jul 23 '14 at 08:46

2 Answers2

1

use this code

        UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        viewcontroller *obj = [story instantiateViewControllerWithIdentifier:@"viewcontrollerID"];


        [self.navigationController pushViewController:obj animated:YES];

for this you have to give storyboard id. for that see my answer on this link for storyboardID

Community
  • 1
  • 1
Max
  • 2,269
  • 4
  • 24
  • 49
  • Or you could tell them how to do it in this answer. People don't going to over resources in answers so please include, since you refer to it in your answer your answer is incomplete without it. Also why are you getting a new instance of the storyboard they should already have an instance from `self.storyboard`. Your code would use unnecessary memory. – Popeye Jul 23 '14 at 07:36
  • Ya sure, Thanks for it. Good one. – Max Jul 23 '14 at 08:18
1

try like this it may help you.

NSMutableArray * highScores = [defaults objectForKey:@"high_scores"];

    for(NSNumber * score in highScores) {
        NSLog(@"Score: %i", [score intValue]);
        if (score >=100) {
            --> OPEN A SPECIFIC UIVIEWCONTROLLER ON THE STORYBOARD
 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
        YourViewcontroller*  detail = [storyboard instantiateViewControllerWithIdentifier:@"YourViewcontroller"];
        [self presentViewController:detail animated:YES completion:nil];

 NSLog(@">100");

        }
    }
Iphonenew
  • 299
  • 2
  • 11
  • Why are you getting a new instance of the storyboard they should already have an instance from `self.storyboard`. Your code would use unnecessary memory. – Popeye Jul 23 '14 at 07:40