NSMutableArray only works in viewdidload
i have a NSMutableArray set up in one of my superclasses, and all of the subclasses of that superclass use it. A problem im having is the array only works in the viewdidload, when i want it to be in a IBAction. If the array isnt in the viewdidload, it comes back with a count of 0
nibs = [[NSMutableArray alloc]initWithObjects:@"Question 1", @"Question 2", @"Question 3", @"Question 4", @"Question 5", @"Question 6", @"Question 7", @"Question 8", @"Question 9", @"Question 10", @"Question 11", @"Question 12", @"Question 13", @"Question 14", @"Question 15", nil];
self.unusedNibs = nibs;
[nibs release];
Here is something that could be related to this, i have the super class and sub class things set up weird, let me show you
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
int score;
int usedQ1;;
int usedQ2;
int usedQ3;
int usedQ4;
int usedQ5;
int usedQ6;
int usedQ7;
int usedQ8;
int usedQ9;
int usedQ10;
int usedQ11;
int usedQ12;
int usedQ13;
int usedQ14;
int usedQ15;
int randomQ1;
int randomQ2;
int randomQ3;
int randomQ4;
int randomQ5;
int randomQ6;
int randomQ7;
int randomQ8;
int randomQ9;
int randomQ10;
int randomQ11;
int randomQ12;
int randomQ13;
int randomQ14;
int randomQ15;
int correct;
NSMutableArray *nibs;
NSMutableArray *unusedNibs;
int skip;
int world;
int politics;
int tv;
UIButton *worldButton;
UIButton *politicsButton;
UIButton *starButton;
@interface HowToPlay : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
UIPickerView *selectType;
NSMutableArray *selectArray;
AVAudioPlayer *audioPlayer;
UIActivityIndicatorView *progress;
}
@property (readwrite) int world;
@property (readwrite) int politics;
@property (readwrite) int tv;
@property (readwrite) int ammountQ;
@property (nonatomic, retain) IBOutlet UITextField *setQs;
@property (nonatomic, retain) NSMutableArray *nibs;
@property (nonatomic, retain) NSMutableArray *unusedNibs;
@property (nonatomic, retain) IBOutlet UIButton *worldButton;
@property (nonatomic, retain) IBOutlet UIButton *politicsButton;
@property (nonatomic, retain) IBOutlet UIButton *starButton;
@property (nonatomic, retain) IBOutlet UIPickerView *selectType;
@property (nonatomic) int usedQ1;
@property (nonatomic) int usedQ2;
@property (nonatomic) int usedQ3;
@property (nonatomic) int usedQ4;
@property (nonatomic) int usedQ5;
@property (nonatomic) int usedQ6;
@property (n开发者_开发百科onatomic) int usedQ7;
@property (nonatomic) int usedQ8;
@property (nonatomic) int usedQ9;
@property (nonatomic) int usedQ10;
@property (nonatomic) int usedQ11;
@property (nonatomic) int usedQ12;
@property (nonatomic) int usedQ13;
@property (nonatomic) int usedQ14;
@property (nonatomic) int usedQ15;
@property (readwrite) int score;
-(IBAction)World:(id)sender;
- (IBAction)Politics:(id)sender;
-(IBAction)Stars:(id)sender;
@end
#import "MainViewController.h"
#import "Question 1.h"
#import "Question 2.h"
#import "Question 3.h"
#import "Question 4.h"
#import "Question 5.h"
#import "Question 6.h"
#import "Question 7.h"
#import "Question 8.h"
#import "Question 9.h"
#import "Question 10.h"
#import "Question 11.h"
#import "Question 12.h"
#import "Question 13.h"
#import "Question 14.h"
#import "Question 15.h"
#import "Game Over.h"
is it just me, or is this set up weird. if i dont import after the '@end' i get errors, and if i dont initialize my variables above the '@interface' i get errors. Anyone want to help me out?
Thanks
Start by putting your variables inside the:
@interface HowToPlay : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
//...
}
It should work after that.
精彩评论