我正在創建一個iPad應用程序,在此我動態地在設備中創建接口,這裏是代碼。如何分配名稱以在iPad應用程序中動態創建對象
- (void)setUpInterface{
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 10,self.view.frame.size.width-20, self.view.frame.size.height-20)];
int y = 0;
for (int i=0; i < [labelArray count]; i++) {
y=y+75;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, y, 500, 30)];
label.text = [NSString stringWithFormat:@"%@",[labelArray objectAtIndex:i]];
label.backgroundColor = [UIColor clearColor];
label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[scrollview addSubview:label];
UITextField *textBox = [[UITextField alloc]initWithFrame:CGRectMake(200, y, 500, 30)];
textBox.borderStyle = UITextBorderStyleRoundedRect;
textBox.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[scrollview addSubview:textBox];
}
scrollview.contentSize = CGSizeMake(self.view.frame.size.width-100, y*2);
scrollview.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
scrollview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:scrollview];
}
在當我點擊一個按鈕,我想最終獲得在每個文本框中分別輸入的數據。我怎樣才能實現呢?如何爲每個對象分配名稱? 謝謝。
當您按下按鈕時,您是否想要在所有texfields中獲取文本?或者當您按下按鈕時,您想要在特定文本字段中獲取文本? – janusbalatbat 2012-03-13 07:21:08
我想從所有文本字段中獲取文本,當我按下按鈕 – Mithuzz 2012-03-13 07:31:32
時使用快速枚舉。張貼我的答案 – janusbalatbat 2012-03-13 07:35:57