简体   繁体   中英

IOS navigate to new view but get a black screen

I have navigate to a new class with view by the below table view delegate method but I get a black screen returned.

#import "NewClass.h"

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName: @"MainStoryboard" bundle: [NSBundle mainBundle]];
    NewClass *new = [storyboard instantiateViewControllerWithIdentifier: @"newDetail"];
    new.array = localArray;
    [self presentViewController: new animated: YES completion: nil];
}

I have NSLog the array on the new class there and the data is received in the new class, all the storyboard name, identifier tag are correct placed, but I don't know why I still getting a black screen, could anyone help me point out what is the error cause there?

try this code:

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath 
{
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    NewClass * new = [storyboard instantiateViewControllerWithIdentifier:@"newDetail"];
new.array = localArray;
    [self.navigationController pushViewController:new animated:YES];
}

It should be,

ViewController *new = [storyboard instantiateViewControllerWithIdentifier: @"newDetail"];

And make sure the id of your view controller is set to newDetail on storyboard

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM