views:

52

answers:

1

I have 4 UITextFields that I'm dynamically creating, in the viewDidLoad, which works good. I want to reference those objects when the UISlider value changes. Right now I'm storing those objects in a NSMutableArray and accessing them like so from the sliderChanged method:

    NSInteger labelIndex = [newText intValue];
labelIndex--;

NSUInteger firstValue = (int)0;

NSMutableArray *holeArray = [pointsArray objectAtIndex:labelIndex];
UITextField *textField = [textFieldArray objectAtIndex:firstValue];
NSString *newLabel1Text = [[NSString alloc] initWithString:[[holeArray objectAtIndex:firstValue] stringValue]];

[textField setText: newLabel1Text];

[newLabel1Text release];

Everything is working good, but the program crashes on the setText: method. The last message I get from the program is: [UILabel drawTextInRect:] and then I get a EXC_BAD_ACCESS failure.

I want to be able to acces that dynamically created UITextField, but I must be going about it the wrong way.

Thanks!

A: 

Uh, yea, you create a text field, but you aren't displaying the field itself, just creating it.

If you want to do what I think you want to do, I would just do if statements.

ex.

if (firstValue == 1)
{
 fieldone.text = @"whatever";
}
else if (firstValue == 2)
{
fieldtwo.text = @"whatever";
}
Matt S.
The text fields have been added to the view. I'm trying to access them dynamcially, and set their text properties. I saw a posting about accessing objects by their tag property. Would that be a better way to go?
Beanwah
the fields may have been added, but your code is creating a NEW textfield (hence the `UITextField *`) and you probably could use tags, but I wouldn't
Matt S.
Thanks Matt. I changed it to use tags and it's working wonderfully!
Beanwah