這樣根據(jù)數(shù)據(jù)信息,動態(tài)創(chuàng)建了一堆UITextField,每一個UITextField都對應(yīng)了一個UIButton。for(i=0; i<[users count]; i++)
{ NSString *name = [users objectAtIndex:i]; UITextField *user = [[UITextField alloc] initWithFrame:CGRectMake(0.f, top, 200.f, 30.f)];
user.text = name;
user.returnKeyType = UIReturnKeyDone;
user.keyboardType = UIKeyboardTypeDefault; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(220.f, top, 80.f, 30.f)];
[btn addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
[self.scroller addSubview:user];
[self.scroller addSubview:btn];
top = top + 40;
}現(xiàn)在要通過點擊某個Button,修改對應(yīng)的UITextField的值
1 回答
呼喚遠(yuǎn)方
TA貢獻1856條經(jīng)驗 獲得超11個贊
創(chuàng)建時
for(i=0; i<[users count]; i++)
{ NSString *name = [users objectAtIndex:i]; UITextField *user = [[UITextField alloc] initWithFrame:CGRectMake(0.f, top, 200.f, 30.f)]; //注意這句
user.tag = i; //注意上面這句
user.text = name;
user.returnKeyType = UIReturnKeyDone;
user.keyboardType = UIKeyboardTypeDefault; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(220.f, top, 80.f, 30.f)];
[btn addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
[self.scroller addSubview:user];
[self.scroller addSubview:btn];
top = top + 40;
}獲取時
UITextField *user = [self.scroller viewWithTag:i];
另建議將user命名為userTextField
- 1 回答
- 0 關(guān)注
- 182 瀏覽
添加回答
舉報
0/150
提交
取消
