Note that there are some explanatory texts on larger screens.

plurals
  1. POxcode iphone save reference to UIButtons in NSMutableArray
    primarykey
    data
    text
    <p>I have a ViewController with many .xib-Files (UIViews) and lots of UIButtons. So the idea is to save them in an Array[ViewID][ButtonID] to easy access them using counters, numbers etc.</p> <pre><code>***ViewController.h IBOutlet UIButton *button0101; IBOutlet UIButton *button0102; IBOutlet UIButton *button0103; IBOutlet UIButton *button0201; ... NSMutableArray *buttonsArray; ... @property (nonatomic, retain) IBOutlet UIButton *button0101; @property (nonatomic, retain) IBOutlet UIButton *button0102; @property (nonatomic, retain) IBOutlet UIButton *button0103; @property (nonatomic, retain) IBOutlet UIButton *button0201; ... @property (nonatomic, retain) NSMutableArray *buttonsArray; ***ViewController.m @synthesize allThoseButtons/Arrays; ... -(void)viewDidLoad { self.buttonsArray = [[NSMutableArray alloc] init]; NSMutableArray *helpArray = [[NSMutableArray alloc] init]; [helpArray addObject:self.button0101]; [helpArray addObject:self.button0102]; [helpArray addObject:self.button0103]; [self.buttonsArray addObject:helpArray]; [helpArray removeAllObjects]; [helpArray addObject:self.button0201]; ... [self.buttonsArray addObject:helpArray]; [helpArray removeAllObjects]; ... </code></pre> <p>I can access the array, I can output the correct predefined titles of the buttons etc, but I can not change the buttons (i.e. backgroundimage, titleLabel etc) while accessing them using the buttonsArray.</p> <pre><code>-(IBAction)pushButton:(id)sender { //this does work [(UIButton *)sender setTitle:@"Test" forState:UIControlStateNormal]; //this has no effect at all (even if I have chosen the correct button in the array, I can check that using the predefined tag and title) [(UIButton *)[helpButtons objectAtIndex:index2] setTitle:@"Test" forState:UIControlStateNormal]; } </code></pre> <p>It seems as if the reference saved in the NSMutableArray is not the same as in InterfaceBuilder but a new object. If I output the object with NSLog directly, I can even see another memory-ID. But what did I do wrong? How can I save the real reference in an Array to access those buttons?</p> <p>Thanks and regards, Pat</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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