本文介绍了IOS Segue - 终止应用程序由于未捕获的异常'NSGeneric异常'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
故事板截图
Storyboard screenshot
在Xcode 4.6故事板中,我有2个ViewControlers,一个保存按钮,另一个是LabelView,在主屏幕按钮上传递一个字符串Home Tapped
In the Xcode 4.6 Storyboard i've 2 ViewControlers, one which holds the buttons and the other a labelView, passing a string "Home Tapped" on the tap of the home button
属于ViewController.m代码
Heres the ViewController.m code
#import "ViewController.h"
#import "ViewController2.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"Home"])
{
NSString *message = @"Tapped on home";
ViewController2 *vc = [segue destinationViewController];
vc.labelString = message;
}
}
ViewController2.h
ViewController2.h
#import <UIKit/UIKit.h>
@interface ViewController2 : UITableViewController
@property(nonatomic,strong) UILabel *mylabel;
@property(nonatomic,strong) NSString *labelString;
@end
而且错误
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'Home'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x468f31 0x45ab99 0x45ac14 0x10e2705 0x162c0 0x16258 0xd7021 0xd757f 0xd66e8 0x45cef 0x45f02 0x23d4a 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1beb7e3 0x1beb668 0x12ffc 0x28dd 0x2805)
libc++abi.dylib: terminate called throwing an exception
(lldb)
推荐答案
您需要使您的 NavigationController
故事板现在它是 View Controller
,由箭头指向的没有来源。
You need to make your NavigationController
the entry point for your storyboard. Right now it is View Controller
, which is indicated by the arrow pointing to it with no source.
这篇关于IOS Segue - 终止应用程序由于未捕获的异常'NSGeneric异常'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!