我试图从NSObject类的不同类调用performSegueWithIdentifier,我收到此错误:
因未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:
'Receiver (<DerinlikView: 0x95b1ac0>) has no segue with identifier 'DerinlikToPali''
Run Code Online (Sandbox Code Playgroud)
我的代码是:
Class1(NSObject):
DerinlikView *derinlik = [DerinlikView alloc];
[derinlik performSegue];
Run Code Online (Sandbox Code Playgroud)
Class2(UIViewController):
- (void) performSegue
{
[self performSegueWithIdentifier:@"DerinlikToPali" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ( [[segue identifier] isEqualToString:@"DerinlikToPali"] )
{
Palinolojik *pali = segue.destinationViewController;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我遇到了同样的问题,我设法通过使用NSNotificationCenter来解决它.
在NSObject类.m文件中,我添加了:
[[NSNotificationCenter defaultCenter] postNotificationName:@"performsegue"
object:nil];
Run Code Online (Sandbox Code Playgroud)
在ViewController类.m文件中 -
1.在 - (void)viewDidLoad中我添加了:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(performsegueNotification:)
name:@"performsegue"
object:nil];
Run Code Online (Sandbox Code Playgroud)
2.在 - (void)viewDidUnload中我添加了:
[[NSNotificationCenter defaultCenter] removeObserver:self];
Run Code Online (Sandbox Code Playgroud)
3.处理方法执行报告通知:
-(void)performsegueNotification:(NSNotification *) notif
{
[self performSegueWithIdentifier: @"PresentView" sender:self];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3813 次 |
| 最近记录: |