Iphone 如何动态生成具有不同名称的UITextFields并从其他位置访问它?

Iphone 如何动态生成具有不同名称的UITextFields并从其他位置访问它?,iphone,nsmutablearray,uitextfield,dynamic,Iphone,Nsmutablearray,Uitextfield,Dynamic,我有一个iPhone应用程序,其中有动态生成的文本字段来捕获产品数量的值。默认数量为1。我已经生成了这样的文本字段 for(int i=0;i<[array count];i++) { UITextField *i=[[UITextField alloc]init]; i.frame=CGRectMake(90, Yposqtytextfield, 60, 30); i.borderStyle=UITextBorderStyleRoundedRect; [s

我有一个iPhone应用程序,其中有动态生成的文本字段来捕获产品数量的值。默认数量为1。我已经生成了这样的文本字段

for(int i=0;i<[array count];i++)
{
    UITextField *i=[[UITextField alloc]init];
    i.frame=CGRectMake(90, Yposqtytextfield, 60, 30);
    i.borderStyle=UITextBorderStyleRoundedRect;
    [self.scrollview addSubview:i];

    i.delegate=self;
    i.text=@"1";
    i.tag=i;
    [appDelegate.qtyArray addObject:i.text];
}
for(int i=0;i
应该是

NSString *aValue = [appDelegate.qtyArray objectAtIndex:0];
NSString *aValue = [appDelegate.qtyArray objectAtIndex:0];

因为他是在添加textfield的值,而不是textfield对象本身。

您可以在应用程序中的任何位置访问您的qtyArray。因为应用程序委托是单例类。您可以这样访问值

for(int i=0;i<[array count];i++)
{
    UITextField *i=[[UITextField alloc]init];
    i.frame=CGRectMake(90, Yposqtytextfield, 60, 30);
    i.borderStyle=UITextBorderStyleRoundedRect;
    [self.scrollview addSubview:i];

    i.delegate=self;
    i.text=@"1";
    i.tag=i;
    [appDelegate.qtyArray addObject:i.text];
}