程序因未知原因而崩溃

时间:2013-03-30 16:59:28

标签: ios xcode uiviewcontroller crash segue

我无法弄清楚为什么会发生这种错误。我已经好几天了。 我有一个名为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)

1 个答案:

答案 0 :(得分:0)

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

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

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

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