cactus62
cactus62

Reputation: 71

AlertView directing to new UIView

I'm simply trying to make it so when the first button of an alert view is pressed, another UIView comes up.

So far I've done this but all I get is a black screen after the button is pressed. The second UIView is called ResultsViewController.

Where am I going wrong? Any help appreciated!

At the top:

@class ResultsViewController;
ResultsViewController *ResultsviewController;

Then:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 0){


        UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
        [self presentViewController:ResultsviewController animated:YES completion:nil];
    }
    if(buttonIndex == 1){

        [self startRunning];
    }
}

Upvotes: 0

Views: 51

Answers (2)

Greg
Greg

Reputation: 25459

You declarer ResultsViewController *ResultsviewController; and after that you do it again:

UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];

Why is a reason to do that? You don't have to call initWithNibName: bundle: if you don't provide nib name. Replace this line:

UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];

with that one:

UIViewController *ResultsviewController = [[UIViewController alloc] init];
//your code to present result view controller

// EXTENDED

Try move the two lines to new method, for example:

-(void)openNewView {
    UIViewController *ResultsviewController = [[UIViewController alloc] init];
    [self presentViewController:ResultsviewController animated:YES completion:nil];
}

and call it with delay when button is clicked:

[self performSelector:@selector(openNewView) withObject:nil afterDelay:0.5];

Upvotes: 0

Flexicoder
Flexicoder

Reputation: 8511

These 2 lines are just creating a UIViewControler

    UIViewController *ResultsviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    [self presentViewController:ResultsviewController animated:YES completion:nil];

you need

   ResultsViewController  * ResultsviewController = [[ResultsViewController alloc] initWithNibName:nil bundle:nil];
    [self presentViewController:ResultsviewController animated:YES completion:nil];

Upvotes: 1

Related Questions