我有以下按钮作为我的navigationRightBarItem:
UIBarButtonItem *menubutton1 = [[UIBarButtonItem alloc] initWithImage:menuimage1 style:UIBarButtonItemStylePlain target:self action:@selector(toCheckIn)];
和
-(void) toCheckIn
{ NotificationsViewController *notificationViewController = [[NotificationsViewController alloc]init];
[self.navigationController pushViewController:notificationViewController animated:YES]; }
我正在尝试推送的视图控制器(通知控制器)包含导航栏,标签和表格。当我按下按钮时,视图被推动但不完全。仅显示导航栏和标签,但表格仅显示为黑色屏幕。
其他人碰巧遇到过同样的事情吗?我该如何解决这个问题?
编辑:表格被拖到故事板上,而标签和导航栏由代码完成。这可能是一个问题吗?
答案 0 :(得分:0)
我认为有几件事会让你朝着正确的方向前进:
好像你没有在故事板中从SourceViewController
到NotificationsViewController
创建一个segue。对于你正在做的事情,它会极大地简化这个过程。
要创建一个segue,您只需按住CTRL键点击SourceViewController
的{{1}}并拖动到UIBarButtonItem
,然后放开,然后选择push作为segue类型。如果您需要将数据传递给NotificationsViewController
,我还会在属性检查器中为此segue提供一个标识符,以便以后与NotificationsViewController
一起使用。
现在,当你的prepareForSegue
被推送UIBarButton
时,会通过storyboard实例化它,然后将其推送到ViewController堆栈。
这也是我认为您没有在视图中看到NotificationsViewController
的原因,因为如果您只是将其拖到故事板上并且未将其设置为UITableView
的属性,在代码中创建全新实例以推送到ViewController堆栈将导致它只知道您在代码中添加的子视图。