0

我无法弄清楚为什么会发生此错误。我已经坚持了好几天了。我有一个名为 ADViewController 的 VC,它显示来自 plist 文件的问题。它有自己的类,是 ViewController 的子类,而不是 UIViewController(这可能值得一提)。我很难执行Segue“LevelCleared”,这是它自己的类ClearedAd1ViewController。如果这是一个愚蠢的问题,我深表歉意,但我自己无法弄清楚。这是 ADViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];
rootArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Addition1" ofType:@"plist"]];
currentQuestion = -1;
[self showNextQuestion];

}
-(void) showNextQuestion{
currentQuestion++;
if (currentQuestion <= 2) {

    int numItems = [rootArray count];
    NSMutableArray *question = [NSMutableArray arrayWithCapacity:numItems];
    NSMutableArray *A = [NSMutableArray arrayWithCapacity:numItems];
    NSMutableArray *B = [NSMutableArray arrayWithCapacity:numItems];
    NSMutableArray *C = [NSMutableArray arrayWithCapacity:numItems];
    NSMutableArray *addimage = [NSMutableArray arrayWithCapacity:numItems];
    NSMutableArray *Answer = [NSMutableArray arrayWithCapacity:numItems];


    for (NSDictionary *itemData in rootArray) {
        [question addObject:[itemData objectForKey:@"question"]];
        [A addObject:[itemData objectForKey:@"A"]];
        [B addObject:[itemData objectForKey:@"B"]];
        [C addObject:[itemData objectForKey:@"C"]];
        [addimage addObject:[itemData objectForKey:@"ImageUse"]];
        [Answer addObject:[itemData objectForKey:@"ANS"]];

    }
    self.questionasked.text = question[currentQuestion];
    self.answer1.text = A[currentQuestion];
    self.answer2.text = B[currentQuestion];
    self.answer3.text = C[currentQuestion];
    additionImage.image = [UIImage imageNamed:addimage[currentQuestion]];
    self.correctAns = Answer[currentQuestion];}
else{
    NSLog(@"End of Array ");
    [self performSegueWithIdentifier:@"LevelCleared" sender:nil];

}
}

我会将 NSLog 消息写入控制台,但不会执行 Segue。当它到达数组中的第 3 项时,我想执行 segue,但我不断收到此错误

 2013-03-30 16:37:15.912 thefyp[1268:c07] End of Array 
2013-03-30 16:37:15.915 thefyp[1268:c07] -[ClearedAd1ViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x757fcd0
2013-03-30 16:37:15.916 thefyp[1268:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ClearedAd1ViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x757fcd0'
***First throw call stack:
 (0x1cb8012 0x10f5e7e 0x1d434bd 0x1ca7bbc 0x1ca794e 0x834b 0x481b87 0x11bdd2 0x8f87 0x9050 0x1109705 0x3d2c0 0x3d258 0xfe021 0xfe57f 0xfd6e8 0x6ccef 0x6cf02 0x4ad4a 0x3c698 0x1c13df9 0x1c13ad0 0x1c2dbf5 0x1c2d962 0x1c5ebb6 0x1c5df44 0x1c5de1b 0x1c127e3 0x1c12668 0x39ffc 0x2a8d 0x29b5 0x1)
 libc++abi.dylib: terminate called throwing an exception

(lldb)

4

1 回答 1

0

我认为您非常困惑我认为您想说的是 ADViewController 是 UIView 的子类而不是 ViewController 类。在这种情况下

[self performSegueWithIdentifier:@"LevelCleared" sender:nil];

不能调用,因为它是视图控制器方法而不是 UIView 方法。这就是错误说选择器被识别的原因。

因此,您需要在 UIView 控制器中实现代码来解决此问题。

于 2013-03-30T19:30:58.887 回答