It looks like you're new here. If you want to get involved, click one of these buttons!
#import \"instanceTestViewController.h\"
#import \"otherClass.h\"
NSMutableArray *OptionSet;
- (void)viewDidLoad
{
[super viewDidLoad];
OptionSet = [[NSMutableArray alloc] init];
[self makeInstances];
[self setInstanceColors];
[self showColors];
}
-(void)makeInstances
{
otherClass *Temp = [[otherClass alloc] init];
for( int i = 0; i < 6; i++ )
{
[OptionSet addObject:Temp];
}
[Temp release];
}
-(void)setInstanceColors
{
// should call the load method of each instance, and set each \"myColor\"
for (int i = 0; i < 6; i++){
temp = [OptionSet objectAtIndex:i];
[temp load];
[temp set_myColor:[UIColor yellowColor]];
}
temp = [OptionSet objectAtIndex:0];
/* If the next line is quoted out, then \"showColors\" changes all the boxes'
background color to yellow. But if it is left in, all boxes show as blue. */
[temp set_myColor:[UIColor blueColor]];
[temp release];
}
-(IBAction)showColors
{
otherClass *temp = [[otherClass alloc] init];
temp = [OptionSet objectAtIndex:0];
[box1 setBackgroundColor:[temp get_theColor]];
temp = [OptionSet objectAtIndex:1];
[box2 setBackgroundColor:[temp get_theColor]];
temp = [OptionSet objectAtIndex:2];
[box3 setBackgroundColor:[temp get_theColor]];
[temp release];
}
#import \"Color.h\"
@implementation Color
UIColor *myColor;
-(void)load
{
myColor = [[UIColor alloc] init];
}
-(void)set_myColor:(UIColor*)newcolor
{
myColor = newcolor;
}
-(UIColor*)get_theColor
{
return myColor;
}
#import <UIKit/UIKit.h>
@interface CrackTheCodeHelperViewController : UIViewController {
IBOutlet UITextField *box1;
IBOutlet UITextField *box2;
IBOutlet UITextField *box3;
}
@property (nonatomic, retain) UITextField *box1;
@property (nonatomic, retain) UITextField *box2;
@property (nonatomic, retain) UITextField *box3;
// each of the boxes is attached appropriately in my .xib file
@end
Replies
Perform looping in "viewDidLoad" where you call "[self makeInstances]"
You Think, We Create...
http://iosdeveloperz.com/
<a hre
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeDo this:
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou Think, We Create...
http://iosdeveloperz.com/
<a hre
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomethis still produces the same results. so far, when ever i call the "set_myColor", it changes the color of all the instances of otherClass.
I have also tried making the instances manually (without a loop), which yielded the same results. I also called set_myColor individually instead of a loop, which also had the same results.
Could it still be that they are technically the same instance? could it be an issue with how I have set up the "otherClass"? if it helps, I haven't added anything to otherClass.h. Should i place my methods and variables in the .h?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNEW CODE
Thanks again to both of you for your insight :D
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome