iOS UIBarButtonItem link 到 ViewController
iOS UIBarButtonItem link to ViewController
我对 Storyboard 中的 UIBarButtonItem
到 link 到另一个 ViewController 有疑问。在此顶部栏中,右侧有 2 个图标,使用数组执行此操作:
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_meetupButton, _searchButton, nil]];
两个按钮在控制台中都可以使用,但是当我想使用 meetupButton
导航到另一个 ViewController 时,它不起作用。
故事板名称是 Main
ViewController 正确地 link 编辑为 MeetupStartViewController
。
当他运行以下代码时,他崩溃了。我做错了什么?
- (void)toggleMeetup:(UIButton *)button {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"MeetupStartViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
错误日志:
2015-09-08 15:46:46.554 APPNAME[2267:530587] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'MeetupStartViewController''
* First throw call stack:
(0x184e9022c 0x196b640e4 0x189eced3c 0x1000f90f0 0x1899411ec 0x1899411ec 0x18992a2c8 0x189940b88 0x189940814 0x189939d50 0x18990cf74 0x189bae124 0x18990b488 0x184e47f8c 0x184e47230 0x184e452e0 0x184d70f74 0x18e7cb6fc 0x189972d94 0x1000a2764 0x19720ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
MeetupStartViewController
是 Swift class 另一个代码是 Objective-C.
您似乎没有为 MeetupStartViewController 设置所需的 ID。
为此,请进入故事板,select MeetupStartViewController。
选中以下复选框:使用 Storyboard ID 并在 StoryboardID 框中写入 "MeetupStartViewController"。这是一个视觉示例:
我对 Storyboard 中的 UIBarButtonItem
到 link 到另一个 ViewController 有疑问。在此顶部栏中,右侧有 2 个图标,使用数组执行此操作:
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_meetupButton, _searchButton, nil]];
两个按钮在控制台中都可以使用,但是当我想使用 meetupButton
导航到另一个 ViewController 时,它不起作用。
故事板名称是 Main
ViewController 正确地 link 编辑为 MeetupStartViewController
。
当他运行以下代码时,他崩溃了。我做错了什么?
- (void)toggleMeetup:(UIButton *)button {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"MeetupStartViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
错误日志:
2015-09-08 15:46:46.554 APPNAME[2267:530587] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'MeetupStartViewController''
* First throw call stack:
(0x184e9022c 0x196b640e4 0x189eced3c 0x1000f90f0 0x1899411ec 0x1899411ec 0x18992a2c8 0x189940b88 0x189940814 0x189939d50 0x18990cf74 0x189bae124 0x18990b488 0x184e47f8c 0x184e47230 0x184e452e0 0x184d70f74 0x18e7cb6fc 0x189972d94 0x1000a2764 0x19720ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
MeetupStartViewController
是 Swift class 另一个代码是 Objective-C.
您似乎没有为 MeetupStartViewController 设置所需的 ID。
为此,请进入故事板,select MeetupStartViewController。 选中以下复选框:使用 Storyboard ID 并在 StoryboardID 框中写入 "MeetupStartViewController"。这是一个视觉示例: