NSMutableArray仅适用于viewdidload

时间:2011-07-18 20:16:34

标签: objective-c ios subclass

我在我的一个超类中设置了一个NSMutableArray,并且该超类的所有子类都使用它。我遇到的一个问题是数组只能在viewdidload中工作,当我希望它在IBAction中时。如果数组不在viewdidload中,则返回计数为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];

这可能与此有关,我有超级类和子类的东西设置很奇怪,让我告诉你

#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 (nonatomic) 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"

只是我,还是这个设置很奇怪。如果我在'@end'之后没有导入我得到错误,如果我不在'@interface'之上初始化我的变量,我会得到错误。有人想帮帮我吗?

由于

1 个答案:

答案 0 :(得分:1)

首先将变量放在:

@interface HowToPlay : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {

//...
}

之后它应该可以工作。