gpt4 book ai didi

ios - 是否可以从另一个类调用 performSegueWithIdentifier?

转载 作者:行者123 更新时间:2023-11-29 01:00:02 25 4
gpt4 key购买 nike

我只是构建了一个类来正确管理我的数据库和 JSON 请求。问题是,现在我该如何执行 segue ?

这是我的代码在我看来:

- (IBAction)loginClick:(id)sender
{
NSString *post = [NSString stringWithFormat:@"username=test&password=test"];
[[DataManagement sharedManager] WebServiceLogin:post];
}
- (void) showTypeView
{
[self performSegueWithIdentifier:@"showTypeView" sender:nil];
}

在我的课上:

    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
...
switch ([[response valueForKey:@"success"] intValue])
{
case 0:
{
NSLog(@"error: %@ error Description: %@", [response valueForKey:@"success"], [response valueForKey:@"error_message"]);
break;
}
case 1:
{
LoginViewController *showView = [LoginViewController new];
[showView showTypeView];
break;
}
default:
break;
}
...
}

启动时出现错误:**

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<LoginViewController: 0x165afd30>) has no segue with identifier 'showTypeView''
*** First throw call stack:
(0x2592e2eb 0x250fadff 0x29e2b037 0xe1819 0xdb64f 0x25f64de1 0x25f64d99 0x25f64e8d 0x25e261ef 0x25edf04f 0xa77cab 0xa7f835 0x25e171e3 0x258415f9 0x25e170cb 0x25e16f95 0x25e16e29 0x258f1257 0x258f0e47 0x258ef1af 0x25841bb9 0x258419ad 0x26abbaf9 0x29b2dfb5 0xe3ea9 0x254f4873)
libc++abi.dylib: terminating with uncaught exception of type NSException

**

最佳答案

如果您正在使用 segueWithIdentifier,那么您需要已经在 Storyboard 中构建了 segue 并正确标记为“showTypeView”。否则,您应该使用导航 Controller 来推送 View Controller 或使用 self presentViewController 来显示模态视图 Controller 。

编辑:根据 Larme 的评论,您可以像这样构建一个委托(delegate):

// In your class.h file
@property (weak, nonatomic)id<SegueDelegate> delegate;

// In class.m file
LoginViewController *showView = [LoginViewController new];
self.delegate = showView;
[self.delegate segue];


// In LoginViewController.h
@protocol SegueDelegate
-(void)segue;
@end

@interface LoginViewController: UIViewController <SegueDelegate>
-(void)segue;
@end

// In LoginViewController.m
@implementation LoginViewController
-(void)segue
{
[self performSegueWithIdentifier:@"showTypeView" sender:nil];
}
@end

关于ios - 是否可以从另一个类调用 performSegueWithIdentifier?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37120292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com