gpt4 book ai didi

objective-c - NSMutableArray 仅适用于 viewDidLoad

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

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

这里有一些可能与此相关的东西,我将父类(super class)和子类的东西设置得很奇怪,让我告诉你

#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”上方初始化变量,我会收到错误。有人愿意帮我吗?

谢谢

最佳答案

首先将变量放入:

@interface HowToPlay : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {

//...
}

之后应该可以工作。

关于objective-c - NSMutableArray 仅适用于 viewDidLoad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6738874/

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