gpt4 book ai didi

ios - 区分两个 View Controller

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

我有 3 个 VC。显示问题和答案的 A。当问题被错误选择时,会显示 B;一旦级别明确,就会显示 C。我遇到了从 A-B 和 A-C 的问题。这是我的代码

#import "AViewController.h"
#import "BViewController.h"
#import "CViewController.h"

@interface AViewController ()
@end

下面是实现代码

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
BViewController *incorrect = [segue destinationViewController];
incorrect.currentQuestion = self.currentQuestion;}

//这里 A 正在向 B 发送有关哪个问题回答错误的信息,即当前问题

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

}

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

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:@"levelpassed" sender:nil];

}
}

上面的这个区域是我遇到问题的地方

当级别被清除时,C VC 会显示此错误

[CViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x71cae70
2013-03-30 21:17:31.264 thefyp[14311:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CViewController setCurrentQuestion:]: unrecognized selector sent to instance 0x71cae70'

我知道问题是 A 发现很难区分 segue,并尝试发送有关当前问题的 C 数据,而我想做的只是在 A 完成显示所有问题且没有数据时显示 C就像 A 继续转移到 B 时一样转移。B 和 C 也是 A 的子类。任何帮助将不胜感激

最佳答案

prepareForSegue方法检查segue标识符UIStoryboardSegue.identifier它是否与您的 B 的过渡相匹配-VC。

因为调用performSegueWithIdentifier:@"levelPassed"也会遇到这个方法,并且你没有 B -VC,因此没有currentQuestion .

关于ios - 区分两个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15765794/

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