Note that there are some explanatory texts on larger screens.

plurals
  1. POGaining access to an NSMutableArray
    text
    copied!<p>I am new to arrays and objects. I have a class HowToPlay.h (of course that has a .m also) their i define two arrays </p> <pre><code>NSMutableArray *nibs; NSMutableArray *unusedNibs; @property (nonatomic, retain) NSMutableArray *nibs; @property (nonatomic, retain) NSMutableArray *unusedNibs; </code></pre> <p>then we jump into the .m, i write all the stuff for the arrays,</p> <pre><code>nibs = [[NSMutableArray alloc]initWithObjects:@"Question 2", @"Question 3", nil]; self.unusedNibs = nibs; [nibs release]; </code></pre> <p>Then i also have another class called Question 1, i need to be able to use this array in that class, and be able to change it, but keep the changes on the HowToPlay.m file. </p> <p>here is why, basically this array loads random NIB files, and then deletes them from the array when they have been used. </p> <p>in Question 1.m here is what im doing to use the array</p> <pre><code>random = arc4random() % [self.unusedNibs count]; NSString *nibName = [self.unusedNibs objectAtIndex:random]; [self.unusedNibs removeObjectAtIndex:random]; if (nibName == @"Question 3") { Question_3 *Q3 = [[Question_3 alloc] initWithNibName:@"Question 3" bundle:nil]; Q3.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:Q3 animated:YES]; [Q3 release]; } if (nibName == @"Question 2") { Question_2 *Q2 = [[Question_2 alloc] initWithNibName:@"Question 2" bundle:nil]; Q2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:Q2 animated:YES]; [Q2 release]; } </code></pre> <p>This all seems to work fine, but the problem im having is it seems that objects in the array are not getting deleted, even though this line runs</p> <pre><code>[self.unusedNibs removeObjectAtIndex:random]; </code></pre> <p>I haved tried making it </p> <pre><code>[HowToPlay.unusedNibs removeObjectAtIndex:random]; </code></pre> <p>I get a error saying <code>expected '.' before '.' token</code></p> <p>It seems to me that i have access to read the array, but not to change it. any way to fix this so i can change the array? thanks</p> <p>UPDATE:</p> <p>here is the whole HowToPlay.h file contents:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;AVFoundation/AVFoundation.h&gt; int score; int usedQ1; int usedQ2; int usedQ3; NSMutableArray *nibs; NSMutableArray *unusedNibs; @interface HowToPlay : UIViewController &lt;UIPickerViewDelegate, UIPickerViewDataSource&gt; { UIPickerView *selectType; NSMutableArray *selectArray; AVAudioPlayer *audioPlayer; UIActivityIndicatorView *progress; UIButton *worldButton; UIButton *politicsButton; UIButton *starButton; } @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 (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" </code></pre> <p>I import after because otherwise i get errors</p> <p>Also I have the array set up on theViewDidLoad part of HowToPlay, is this a bad idea?</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; NSURL *click = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/click.wav", [[NSBundle mainBundle] resourcePath]]]; audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:click error:nil]; audioPlayer.numberOfLoops = 1; progress = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; progress.frame = CGRectMake(0.0, 0.0, 30.0, 30.0); progress.center = self.view.center; [self.view addSubview: progress]; usedQ1 = 0; usedQ2 = 0; usedQ3 = 0; selectArray = [[NSMutableArray alloc]init]; [selectArray addObject:@"World"]; [selectArray addObject:@"Politics"]; [selectArray addObject:@"Stars"]; score = 0; nibs = [[NSMutableArray alloc]initWithObjects:@"Question 2", @"Question 3", nil]; self.unusedNibs = nibs; [nibs release]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload