IOS导航到新视图但获得黑屏

时间:2016-04-12 11:55:44

标签: ios objective-c uitableview presentviewcontroller

我已通过下面的表视图委托方法导航到一个带有视图的新类,但是我返回了一个黑屏。

#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];
}

我在新类上有NSLog数组并且在新类中接收数据,所有故事板名称,标识符标签都正确放置,但我不知道为什么我仍然得到黑屏,任何人都可以帮我指出那里的错误原因是什么?

2 个答案:

答案 0 :(得分:1)

试试这段代码:

- (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];
}

答案 1 :(得分:0)

应该是,

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

并确保视图控制器的ID在故事板上设置为newDetail