从另一堂课进行表演 [英] Performing segue from another class

查看:68
本文介绍了从另一堂课进行表演的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从NSObject类的另一个类中调用performSegueWithIdentifier,并且收到此错误:

I am trying to call performSegueWithIdentifier from different class which is NSObject class and I am receiving this error:

由于未捕获的异常"NSInvalidArgumentException"而终止应用程序,原因:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:

 'Receiver (<DerinlikView: 0x95b1ac0>) has no segue with identifier 'DerinlikToPali''

我的代码是:

Class1(NSObject):

Class1 (NSObject):

    DerinlikView *derinlik = [DerinlikView alloc];
    [derinlik performSegue];

Class2(UIViewController):

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

推荐答案

我认为您的故事板或故事没有错,没错.

I believe nothing wrong with your storyboard or your segues , what not.

问题必须是这一行=

DerinlikView *derinlik = [DerinlikView alloc];

当您为Class2分配新的viewcontroller指针时,它找不到与视图连接的segue.

When you allocate a new viewcontroller pointer for your Class2 it cant find the segue connected to your view.

一种解决方案是将启动的Class2的指针传递给NSObject类.

A solution would be to pass the pointer of your initiated Class2 to NSObject class.

在您的class1.h中:

in your class1.h:

@interface Class1 : NSObject
{
    Class2 *viewController;
}

@property (nonatomic,strong) Class2 *viewController;

在class1.m

@synthesize viewController;

[self.viewController performSegue];

在class2.m中:

In class2.m:

Class1 *callNsObject= [[Class1 alloc] init];
UIViewController *currentVC=self;//this is the part you need the pass current viewcontrollers pointer to your nsobject class depends on your project thee are multiple ways of doing it.
callNsObject.viewController=currentVC;

重要提示:我不知道您的Class2视图控制器的层次结构,因此在UIViewController *currentVC=self;行中,您必须将self更改为当前的视图控制器指针.

Important : I dont know hierarchy of your Class2 viewcontroller so in the line UIViewController *currentVC=self; you have to change self to your current view controller pointer.

例如,如果它是基于导航的应用程序,则可以通过以下方式获取当前的视图控制器: UIViewController *currentVC = self.navigationController.visibleViewController;

For example If it is a navigation based app, you can get the current view controller by, UIViewController *currentVC = self.navigationController.visibleViewController;

我还假设您在调用Class1方法之前将Class2的视图压入堆栈

Also I am assuming that your Class2's view is pushed to stack before you call your Class1 method

这篇关于从另一堂课进行表演的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆