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];
}
最後にボタンをクリックすると、各テキストボックスに入力されたデータを個別に取得したいと考えています。私はそれをどのように実装できますか?各オブジェクトに名前を割り当てる方法は?おかげさまで
ボタンを押したときにすべてのテキストフィールドにテキストを入力しますか?ボタンを押したときに特定のテキストフィールドでテキストを取得したいのですか? – janusbalatbat
ボタンを押すとすべてのテキストフィールドからテキストを取得したい – Mithuzz
高速列挙を使用します。私の答えは – janusbalatbat