这样根据数据信息,动态创建了一堆UITextField,每一个UITextField都对应了一个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;
}现在要通过点击某个Button,修改对应的UITextField的值
1 回答
呼唤远方
TA贡献1856条经验 获得超11个赞
创建时
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 关注
- 120 浏览
添加回答
举报
0/150
提交
取消