开发者

How to generate UITextFields dynamically with different name and accessing it from another place?

I have an iPhone application in which there are dynamically generated textfields to capture a value of product quantity. The default quantity is 1. I have generated textfields like this

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

But I want values of quantities in next page. For that I have taken this qtyarray. Now the user is allowed to change quantity. So how can I change the value of quantity in the array. as declaration of textfield is local to that loop.开发者_Python百科 So at next page navigation how can i get the values of all these textfields?


UITextField *aField = (UITextField*)[appDelegate.qtyArray objectAtIndex:0]

it should be

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

because he is adding value of textfield not the textfield object itself.


you can access your qtyArray anywhere in the application. Since application delegate is singleton class. You can access value like this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜