从Objective-C中的数组访问UITextField

时间:2010-09-23 20:03:23

标签: iphone nsmutablearray

我在viewDidLoad中动态创建了4个UITextField,效果很好。我希望在UISlider值更改时引用这些对象。现在我将这些对象存储在NSMutableArray中,并从sliderChanged方法中访问它们:

    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];

一切都运行良好,但程序在setText:方法崩溃。我从程序中得到的最后一条消息是:[UILabel drawTextInRect:]然后我得到一个EXC_BAD_ACCESS失败。

我希望能够访问动态创建的UITextField,但我必须以错误的方式进行操作。

谢谢!

1 个答案:

答案 0 :(得分:0)

呃,是的,你创建了一个文本字段,但是你没有显示字段本身,只是创建它。

如果你想做我认为你想做的事,我会做if语句。

离。

if (firstValue == 1)
{
 fieldone.text = @"whatever";
}
else if (firstValue == 2)
{
fieldtwo.text = @"whatever";
}
相关问题