【问题标题】:performing an segue doesn't works执行 segue 不起作用
【发布时间】:2014-04-23 19:05:46
【问题描述】:

如果代码与内部定义的代码匹配,我希望应用程序继续。 因此,如果我在文本字段中输入代码,则不会发生任何事情。 你们中的任何人可能对我有一些解决方案吗?

这就是我目前在 ViewController 的 .m 文件中得到的内容

    @interface mainViewController ()
@property (weak, nonatomic) IBOutlet UITextField *zahlencode;
@property (weak, nonatomic) IBOutlet UIButton *done;
@property NSMutableArray *codes;


@end

@implementation mainViewController
- (void)loadInitialData {
    Code *item1 = [[Code alloc] init];
    item1.Code = @"1";
    [self.codes addObject:item1];
}
int a,b,c,zz;
a=1;
b=2;
c=3;

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (sender != self.done)
        return;
    if (self.zahlencode.text.length > 0)
    {
        zz =[self.zahlencode.text intValue];
        if(zz == a)
        {

            [self performSegueWithIdentifier:@"1"];        }
    }
}

【问题讨论】:

  • prepareForSegue:sender:performSegueWithIdentifier: 之后运行。
  • 但我只想判断代码是否正确。之后这也有效吗?

标签: ios objective-c storyboard segue


【解决方案1】:

您的故事板中是否有标识符为“1”的转场?
如果没有,则将其添加到 segue。

你的代码是否到达了performSegueWithIdentifier(你是否做了一个NSLog()来确保代码被执行)?

更新:

你应该试试这个:

从您的 UIButton 中添加一个动作,并在其中编写代码来执行 segue。 (添加情节提要中的动作,如插座)

- (void) ButtonPressed: (id) sender
{
    if (sender != self.done)
        return;
    if (self.zahlencode.text.length > 0)
    {
        zz =[self.zahlencode.text intValue];
        if(zz == a)
        {

            [self performSegueWithIdentifier:@"1" sender:self];
        }
    }
}

【讨论】:

  • 我确实有一个标识符为 1 的 segue。但不是 NSlog 的东西,因为我真的不知道它是如何工作的
  • 这里有一个小例子,你可以用它来查看 performSegueWithIdentifier 是否被执行:NSLog(@"DONE"); 只需在 performSegueWithIdentifier 之前或之后添加它
  • performSegueWithIdentifier 的错误仍然存​​在('mainViewController' 没有可见的@interface 声明选择器'performSegueWithIdentifier:')
  • 我在文本字段中输入了“1”并按下完成,然后出现此错误并且应用程序崩溃:[mainViewController done:]: unrecognized selector sent to instance 0x8d2c610 2014-03-18 10:15:19.983 AbteiRD[6955:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[mainViewController done:]: unrecognized selector sent to instance 0x8d2c610'
  • 能不能切换到Breakpoint Navigator并添加Exeption Breakpoint然后再试一次,这样应该更容易找到问题所在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-13
相关资源
最近更新 更多