這樣根據(jù)數(shù)據(jù)信息,動(dòng)態(tài)創(chuàng)建了一堆UITextField,每一個(gè)UITextField都對(duì)應(yīng)了一個(gè)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)在要通過點(diǎn)擊某個(gè)Button,修改對(duì)應(yīng)的UITextField的值
1 回答

呼喚遠(yuǎn)方
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊
創(chuàng)建時(shí)
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; }
獲取時(shí)
UITextField *user = [self.scroller viewWithTag:i];
另建議將user命名為userTextField
- 1 回答
- 0 關(guān)注
- 159 瀏覽
添加回答
舉報(bào)
0/150
提交
取消