I have 3 VC. A which displays questions and answers. B is displayed when the Question is wrongly selected a C once the level is clear.
I am having an issue going from A-B & A-C.
Here is my code
#import "AViewController.h"
#import "BViewController.h"
#import "CViewController.h"
#interface AViewController ()
#end
Now here is the implementation code
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
BViewController *incorrect = [segue destinationViewController];
incorrect.currentQuestion = self.currentQuestion;}
//Here A is sending B information about which question was answered incorrectly i.e Current Question
- (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];
}
}
This area above here is where I am having the problem
When the the level is cleared C VC is having this error displaying
[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'
I know the issue is that A is finding it hard to differentiate between segue and is trying to send C data about current question when all I want to do is display C when the A is finished showing all questions and no data is being transferred like when A is segueing to B. B & C also is a subclass of A. Any help would be appreciated
In the prepareForSegue method check the segue identifier UIStoryboardSegue.identifier whether it matches the transition to your B-VC.
Because calling performSegueWithIdentifier:#"levelPassed" will also run into this method and there you do not have a B-VC and therefore no currentQuestion.
Related
Hello I'm junior in Objective-C and Swift programming.
I have NSMutableArray in ExampleMenuViewController.m or(and) SomeClass.m declared as vcTabs.
NSMutableArray *vcTabs;
When I have two declares 'vcTabs' Xcode returns duplicate symbol '_vcTabs' (...)
How to add objects to an existing NSMutableArray init in other class (ExampleMenuViewController.m)?
I need append new objects from another class (SomeClass.m) to vcTabs (NSMutableArray).
I wrote in SomeClass.m this code:
if ([Tools isNonullValueForKey:[dictionary valueForKey:#"additional_tabs"]]) {
additional_tabs = [dictionary valueForKey:#"additional_tabs"];
NSLog(#"additionalTabs count: %lu", [additional_tabs count]);
for (int i = 0; i < [additional_tabs count]; i++) {
if ([Tools isNonullValueForKey:[additional_tabs valueForKey:#"_id"]]) {
additional_tab_id = [[additional_tabs valueForKey:#"_id"] objectAtIndex:i];
}
if ([Tools isNonullValueForKey:[additional_tabs valueForKey:#"names"]]) {
NSDictionary *dic = [[additional_tabs valueForKey:#"names"] objectAtIndex:i];
_en_additional_tab_name = [dic valueForKey:#"en"];
_pl_additional_tab_name = [dic valueForKey:#"pl"];
}
if ([Tools isNonullValueForKey:[additional_tabs valueForKey:#"url"]]) {
additional_tab_url = [[additional_tabs valueForKey:#"url"] objectAtIndex:i];
//NSLog(#"additional_tab_url: %#", _additional_tab_url);
}
[vcTabs addObject:[[VCTab alloc] initWithIdAndTypeAndUrl:additional_tab_id :VCTabAdditional :additional_tab_url]];
NSLog(#"%# %d %# %# %# %#", #"pos", i, #"id: ", additional_tab_id, #"url: ", additional_tab_url);
}
}
ExampleMenuViewController method with initVCTabs
- (void)initVCTabs {
vcTabs = [[NSMutableArray alloc] init];
[vcTabs removeAllObjects];
if ([Tools getBooleanUserDefault:#"example_visible_tab_attendees" :YES]) {
[vcTabs addObject:[[VCTab alloc] initWithType:VCTabAttendees]];
}
(...)
if ([Tools getBooleanUserDefault:#"example_visible_tab_user_info" :YES]) {
[vcTabs addObject:[[VCTab alloc] initWithType:VCTabUserInfo]];
}
if ([Tools getStringUserDefault:#"example_additional_tab_id" :#""]) {
NSString *additionalTabId = [Tools getStringUserDefault:#"conference_additional_tab_id" :#""];
NSString *additionalTabUrl = [Tools getStringUserDefault:#"conference_additional_tab_url" :#""];
NSLog(#"additionalTabId %#", additionalTabId);
NSLog(#"additionalTabUrl %#", additionalTabUrl);
[vcTabs addObject:[[VCTab alloc] initWithIdAndTypeAndUrl:additionalTabId :VCTabAdditional :additionalTabUrl]];
}
}
PS. If I use from ExampleMenuViewController I have only one tab with last object properties... but additional_tabs array have 17 objects.
Do you have any ideas or advices?
All the best for you everyone!
When are you calling initVCTabs?
When / how is the code in SomeClass.m running?
For being a "junior in Objective-C and Swift programming" you seem to have a lot going on that you don't understand yet. Try creating a new project and learn how things work -- then implement that in your full project.
Here is a very, very simple example. With the information you provided in your question, this may or may not relate directly - but it should give you an idea of where to go:
SomeClass.h
// SomeClass.h
// Created by Don Mag on 8/30/20.
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#interface SomeClass : NSObject
- (void)moreTabs:(NSMutableArray *)a;
#end
NS_ASSUME_NONNULL_END
SomeClass.m
// SomeClass.m
// Created by Don Mag on 8/30/20.
#import "SomeClass.h"
#interface SomeClass()
#end
#implementation SomeClass
- (void)moreTabs:(NSMutableArray *)a {
[a addObject:#"B"];
[a addObject:#"C"];
[a addObject:#"D"];
[a addObject:#"E"];
}
#end
ExampleMenuViewController.h
// ExampleMenuViewController.h
// Created by Don Mag on 8/30/20.
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
#interface ExampleMenuViewController : UIViewController
#end
NS_ASSUME_NONNULL_END
ExampleMenuViewController.m
// ExampleMenuViewController.m
// Created by Don Mag on 8/30/20.
#import "ExampleMenuViewController.h"
#import "SomeClass.h"
#interface ExampleMenuViewController ()
{
NSMutableArray *vcTabs;
}
#end
#implementation ExampleMenuViewController
- (void)viewDidLoad {
[super viewDidLoad];
// add a button to the view
//UIButton *b = [UIButton new];
UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem];
[b setTitle:#"Tap Me" forState:UIControlStateNormal];
b.frame = CGRectMake(0, 0, 200, 50);
b.center = self.view.center;
[self.view addSubview:b];
[b addTarget:self action:#selector(btnTapped) forControlEvents:UIControlEventTouchUpInside];
[self initVCTabs];
[self logArray];
}
- (void)initVCTabs {
// instantiate NSMutableArray
vcTabs = [NSMutableArray new];
// add one object
[vcTabs addObject:#"A"];
}
- (void)btnTapped {
SomeClass *sc = [SomeClass new];
[sc moreTabs:vcTabs];
[self logArray];
}
- (void)logArray {
NSLog(#"vcTabs has %ld objects", [vcTabs count]);
for (NSString *s in vcTabs) {
NSLog(#"%#", s);
}
}
#end
When ExampleMenuViewController loads, it will add a button to the center of the view, then instantiate the vcTabs array and add one object - #"A".
We log the array to the debug console and see:
vcTabs has 1 objects
A
When you tap the button, an instance of SomeClass will be created, we call the moreTabs method in that class, passing a reference to vcTabs. That method will add 4 objects to the array - #"B" #"C" #"D" #"E".
We then log the array to the debug console and see:
vcTabs has 5 objects
A
B
C
D
E
#DonMag
It's working but I have one question to you. I added for loop to increment. When I add [additional_tabs count] is return nil. Why this method adds the same objects? My code in addMore function:
- (void)moreTabs:(NSMutableArray *)a {
for (int i = 1; i < additional_tab_count; i++) {
NSString *additionalTabId = [Tools getStringUserDefault:#"conference_additional_tab_id" :#""];
NSString *additionalTabUrl = [Tools getStringUserDefault:#"conference_additional_tab_url" :#""];
[a addObject:[[VCTab alloc] initWithIdAndTypeAndUrl:additionalTabId :VCTabAdditional :additionalTabUrl]];
}
}
Do you know how to get THIS "dictionary" or "additional_tabs". I tried but always return nil (looks like a new other instance and is not this dictionary or additional_tabs from initFromJSON). I only managed to make variable additional_tab_count and it's return 17 (correct count), but I'd rather have access to array from additional_tabs declared in if statements.
I'm new to iOS development and am currently studying from video tutorials. I came across a problem with quite a simple app I'm experimenting on.
The problem is with loading pictures to UIImage in a split view control iPad app. The app is based on the XCode master-detail application template. I created an array with NSObject variables and two properties.
#interface Burger : NSObject
#property (nonatomic) NSString *name;
#property (nonatomic) NSString *filename;
#end
- (void)viewDidLoad {
[super viewDidLoad];
photos = [[NSMutableArray alloc]init];
Burger *pic = [[Burger alloc]init];
pic.name = #"Bacon";
pic.filename = #"burger-bacon";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Cheese";
pic.filename = #"burger-cheddar";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Hawaii";
pic.filename = #"burger-hawaii";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Koko z jajkiej kurzym";
pic.filename = #"burger-jajo";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Kozi ser";
pic.filename = #"burger-kozi";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Łosoś";
pic.filename = #"burger-losos";
[photos addObject:pic];
pic = [[Burger alloc]init];
pic.name = #"Vege (Soczewica)";
pic.filename = #"burger-soczewica";
[photos addObject:pic];
}
I want the UImageView nested in DetailView to display a picture of the object chosen in the MasterView controller. I got it to display the pictures in the MasterView table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Burger *current = [photos objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageNamed:[current filename]];
[cell.imageView setImage:image];
self.title = self.currentPhoto.name;
cell.textLabel.text = [current name];
cell.detailTextLabel.text = [current price];
return cell;
}
and it also works when I point to a specific file name:
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
UIImage *image = [UIImage imageNamed: #"burger-bacon"];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
}
}
but when I try to show the picture of the chosen element like this:
- (void)configureView {
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
UIImage *image = [UIImage imageNamed: self.currentPhoto.filename];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
}
}
I get these few lines in the debug area:
2015-06-23 12:13:25.964 SlowFoodiPad[22177:744765] CUICatalog: Invalid asset name supplied: (null)
which means the segues work and the photo files seem to be fine. There seem to be a problem with pointing to the right file to display. Any ideas how to fix it?
OK, I managed to solve the problem partially. I edited prepareForSegue method of MasterViewController:
DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
Burger *c = photos [indexPath.row];
[controller setDetailItem:c];
//this line helped
[controller setCurrentPhoto:c];
The appropriate photos now show, although the debug area keeps showing me this message:
CUICatalog: Invalid asset name supplied: (null)
two identical lines each time I tap on an element in the MasterView table.
Right now it's unclear when "-(void)configureView" is being called. My guess, based on your issue, is that it's actually called before prepareForSegue. Or at least, the very first time, it's being called before you actually have an image. You are checking for "if (self.detailItem)" but you are not checking for if (self.currentPhoto).
So probably the first time configure view is called, there is no self.currentPhoto so it can't be set. Then when the segue is actually prepared (prepareForSegue:) you set the current photo, so then when configure view is called again, it's there.
If you paste more of your view controller code that shows what triggers the segue (probably it's just the storyboard but unclear from what you have above) and when configureView, then we'd know for sure if my guess is correct.
OK, there's some progress. Now I only get two lines of this message and only at initial start of the app:
CUICatalog: Invalid asset name supplied: (null)
I commented out few lines here. Can you see anything else that is causing problems?
- (void)setDetailItem:(id)newDetailItem {
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView {
// Update the user interface for the detail item.
// if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem notes];
// UIImage *image = [UIImage imageNamed:self.currentPhoto.filename];
// [self.currentImage setImage:image];
}
//}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *image = [UIImage imageNamed:self.currentPhoto.filename];
[self.currentImage setImage:image];
self.title = self.currentPhoto.name;
self.detailDescriptionLabel.text = [self.detailItem notes];
// [self configureView];
}
Here's the prepareForSegue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Burger *c = photos [indexPath.row];
[controller setDetailItem:c];
//adding this line helped
[controller setCurrentPhoto:c];
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
controller.navigationItem.leftItemsSupplementBackButton = YES;
}
}
I have 2 VC, one where the users write the data, with textfield or pickerview, and the main screen where i show the data on a tableview. The problem is that when i click on done button, it might call the delegate, but on the first vc, where is implemented, it doesnt receive any call. What should i do? I have been for 2 days trying to find the bug, and nothings happens. Thanks for any Help.
2VC.h
#protocol AddCountryDelegate <NSObject>
#required
-(void)didCreateCountry:(CountryClass*)country;
#end
#interface AddCountryViewController : UIViewController
#property (assign, nonatomic) id<AddCountryDelegate> customDelegate;
2VC.m
- (IBAction)actionDone:(id)sender {
NSString* itemName = self.itemNameTextField.text;
NSString* countryName = self.countryNameTextField.text;
NSDate *countryDate = [datePickerView date];
NSString *daysLeftString = [NSString stringWithFormat:#"%# days", self.daysLeftTextField.text];
NSInteger daysLeftInt = [daysLeftString integerValue];
NSNumber *daysLeft = [NSNumber numberWithInteger:daysLeftInt];
NSString *paymentMethod = self.paymentMethodTextField.text;
CountryClass* newCountryItem =
[[CountryClass alloc] initWithCountryName:countryName countryLogo:#"" itemName:itemName countryDate:countryDate daysLeft:daysLeft andPaymentMethod:paymentMethod];
[self.customDelegate didCreateCountry:newCountryItem];
[self dismissViewControllerAnimated:YES completion:nil];
}
And finally the implementation on the 1st VC:
-(void)didCreateCountry:(CountryClass *)country{
//Add new country-itemCountry - UPDATING OUR MODEL DATA
NSMutableArray *mutableCountries = [self.countries mutableCopy];
[mutableCountries addObject:country];
self.countries = [mutableCountries copy];
//UPDATING THE VIEW
[self.tableView reloadData];
NSLog(#"Created");
[self saveCountriesToDisc];
}
-(void)saveCountriesToDisc{
NSMutableArray* convertedCountries = [NSMutableArray array];
//Converting the model to dictionary
for(CountryClass *country in self.countries)
{
NSDictionary *convertedCountry = [shop countriesToDictionary];
[convertedCountries addObject:convertedCountry];
}
//NOW convertedShows CONTAINS ONLY STRINGS, NUMBERS,
//ARRAYS AND DICTIONARY
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = paths.firstObject;
NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:#"countriesListData.plist"];
//NOW TELL THE ARRAY TO SAVE
[convertedCountries writeToFile:destinationPath atomically:YES];
NSLog(#"Saved");
[self.tableView reloadData];
}
I initialize my delegate on the prepareforsegue
-(void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
if ([segue.identifier isEqualToString:#"AddSegue"]) {
AddCountryViewController* addCountryVC =
segue.destinationViewController;
addCountryVC.customDelegate = self;
}
where in VC1 did you set the customDelegate to self?
also you should set your delegate to weak not assign
I have a method in ViewController.m called getData which is called inside viewDidLoad:
-(void)getData {
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:#"WorkoutHasExercise" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
request.resultType = NSDictionaryResultType;
request.propertiesToFetch = [NSArray arrayWithObjects:#"exerciseName", #"reps", #"sets", nil];
NSPredicate *pred = [NSPredicate predicateWithFormat:#"(workoutName = %#)", _workoutName];
[request setPredicate:pred];
NSManagedObject *matches = nil;
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
if ([objects count] == 0) {
} else {
[_exercises removeAllObjects];
for (int x = 0; x < [objects count]; x++) {
matches = objects[x];
[_exercises addObject:[matches valueForKey:#"exerciseName"]];
[_totalSets addObject:[matches valueForKey:#"sets"]];
[_totalReps addObject:[matches valueForKey:#"reps"]];
[_currentSets addObject:[NSNumber numberWithInteger:0]];
}
}
[_exercisesTableView reloadData];
}
I also have a custom UITableViewCell with two buttons initiated in cellForRowAtIndexPath:
ActiveWorkoutCell *cell = (ActiveWorkoutCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"ActiveWorkoutCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.increaseButton.tag = indexPath.row;
cell.decreaseButton.tag = indexPath.row;
In ActiveWorkoutCell.m I have 2 IBActions for the buttons:
- (IBAction)decreaseSets:(id)sender {
ActiveWorkoutViewController *vc = [[ActiveWorkoutViewController alloc] init];
[vc decreaseSets:[sender tag]];
}
- (IBAction)increaseSets:(id)sender {
ActiveWorkoutViewController *vc = [[ActiveWorkoutViewController alloc] init];
[vc increaseSets:[sender tag]];
}
The IBActions call these 2 methods back in ViewController.m
-(void)increaseSets:(NSInteger)row {
[self getData];
//There will be code here to increase the value of currentSets[row]
}
-(void)decreaseSets:(NSInteger)row {
[self getData]
//Code to decrease value...
}
PROBLEM:
When getData is called from viewDidLoad, it works fine.
The problem occurs when returning to ViewController.m from the IBAction in ActiveWorkoutCell.m.
When I call [self getData] in increaseSets the fetch request returns an empty array. This is what is confusing me - the code works fine when it is first called but not at all when called the second time after the custom cell Action has been triggered.
Here is my viewDidLoad if it helps:
- (void)viewDidLoad {
[super viewDidLoad];
_exercises = [NSMutableArray array];
_totalSets = [NSMutableArray array];
_currentSets = [NSMutableArray array];
_totalReps = [NSMutableArray array];
_titleLabel.text = _workoutName;
_exercisesTableView.allowsSelection = NO;
[self getData];
}
_workoutName is given a value in prepareForSegue in the previous view controller.
I think I found the issue. You are instantiating the "ActivityWorkOutViewController" when the IBAction methods called and it will be a new instance and then in those methods you are calling [self getData] which pointing to the new instance which has no variables instantiated or viewDidLoad happened, so your mutable arrays are not allocated and hence they are empty.
Just use the old instance of the class to get the data.
I am not sure how you are referencing those classes. I am just in a confusion about that. But, you might check the allocations and calling the right class to get the data
Having some difficultly with this one.
I am loading questions, answers, correct answers from a plist. All data is being read in fine and looks like below
- (void)viewDidLoad
{
[super viewDidLoad];
rootArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"question" ofType:#"plist"]];
currentQuestion = -1;
[self showNextQuestion];
}
-(void) showNextQuestion{
currentQuestion++;
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];
if(currentQuestion == 4){
[ self performSegueWithIdentifier:#"levelclear" sender:nil];// here I am performing a segue to indicate that when 4 questions are displayed it will go to this view controller
}
}
I have 3 buttons in my VC, One for each option A,B,C which all have a function
- (IBAction)SelectA:(id)sender {
if ([self.correctAns isEqualToString:#"A"]) {
currentQuestion ++;
[self showNextQuestion];
}
else{
[self performSegueWithIdentifier:#"incorrect" sender:nil];
}
}
- (IBAction)SelectB:(id)sender {
if ([self.correctAns isEqualToString:#"B"]) {
currentQuestion ++;
[self showNextQuestion];
}
else{
[self performSegueWithIdentifier:#"incorrect" sender:nil];
}
}
- (IBAction)SelectC:(id)sender {
if ([self.correctAns isEqualToString:#"C"]) {
currentQuestion ++;
[self showNextQuestion];
}
else{
[self performSegueWithIdentifier:#"incorrect" sender:nil];
}
}
When I answer the question correctly it moves to the next question. However when I answer it incorrectly it goes to the incorrect VC informing of the incorrect question. This VC has a segue when the button is pressed to go back to the question VC(which I made in the storyboard). It does go back to the question VC but simply jumps back to the first question. I know it is something regarding the currentQuestion but not sure what.
Looks like when you segue to the incorrect answer you are destroying the questions view controller, and when yo go back to it, it is re created.