获取UITableView每行中不同的UITextField输入的内容
2015-08-13 18:12
483 查看
转自:http://blog.sina.com.cn/s/blog_9ca91e4a0100xlvu.html
获取UITableView每行中不同的UITextField输入的内容
此博文包含视频 (2012-02-20
11:05:47)转载▼
标签: 杂谈
分类: iPhone
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
static NSString *CellIdentifier =
@"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell ==
nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = [_passwordArray objectAtIndex:row];
CGRect textFieldRect = CGRectMake(0.0,
0.0f, 215.0f,
31.0f);
UITextField *theTextField = [[UITextField alloc] initWithFrame:textFieldRect];
theTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
theTextField.returnKeyType = UIReturnKeyDone;
theTextField.secureTextEntry = YES;
theTextField.clearButtonMode = YES;
theTextField.tag = row;
theTextField.delegate = self;
//此方法为关键方法
[theTextField addTarget:self action:@selector(textFieldWithText:) forControlEvents:UIControlEventEditingChanged];
switch (row) {
case
0:
theTextField.placeholder = @"请输入旧密码";
break;
case
1:
theTextField.placeholder = @"请输入新密码";
break;
case
2:
theTextField.placeholder = @"请再次输入新密码";
break;
default:
break;
}
cell.accessoryView = theTextField;
[theTextField release];
return cell;
}
- (void)textFieldWithText:(UITextField *)textField
{
switch (textField.tag) {
case
0:
self.theOldPassword = textField.text;
break;
case
1:
self.theNewPassword = textField.text;
break;
case
2:
self.theTwiceNewPassword = textField.text;
break;
default:
break;
}
}
//个人觉得上面的写法会有reuse问题,可以使用的时候尝试下
获取UITableView每行中不同的UITextField输入的内容
此博文包含视频 (2012-02-20
11:05:47)转载▼
标签: 杂谈
分类: iPhone
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
static NSString *CellIdentifier =
@"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell ==
nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = [_passwordArray objectAtIndex:row];
CGRect textFieldRect = CGRectMake(0.0,
0.0f, 215.0f,
31.0f);
UITextField *theTextField = [[UITextField alloc] initWithFrame:textFieldRect];
theTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
theTextField.returnKeyType = UIReturnKeyDone;
theTextField.secureTextEntry = YES;
theTextField.clearButtonMode = YES;
theTextField.tag = row;
theTextField.delegate = self;
//此方法为关键方法
[theTextField addTarget:self action:@selector(textFieldWithText:) forControlEvents:UIControlEventEditingChanged];
switch (row) {
case
0:
theTextField.placeholder = @"请输入旧密码";
break;
case
1:
theTextField.placeholder = @"请输入新密码";
break;
case
2:
theTextField.placeholder = @"请再次输入新密码";
break;
default:
break;
}
cell.accessoryView = theTextField;
[theTextField release];
return cell;
}
- (void)textFieldWithText:(UITextField *)textField
{
switch (textField.tag) {
case
0:
self.theOldPassword = textField.text;
break;
case
1:
self.theNewPassword = textField.text;
break;
case
2:
self.theTwiceNewPassword = textField.text;
break;
default:
break;
}
}
//个人觉得上面的写法会有reuse问题,可以使用的时候尝试下
相关文章推荐
- MySQL 5.6 中TIMESTAMP with implicit DEFAULT value is deprecated错误
- 【Android和iOS】快速切换到主线程更新UI
- UITabBarController
- AutoLayout初战----Masonry与FDTemplateLayoutCell实践
- UITextField总结
- UI 06 ScrollView 的手动循环播放 与 自动循环播放
- 判断UITableView是否滑到底部
- UILabel 总结
- UITextField
- Uiautomator——实例分析——唯品会的优物
- IOS上 关于状态栏的相关设置(UIStatusBar)
- IOS Using UIAlertView to show alerts
- 黑马程序员 oc随记 NSNumber、NSValue与NSDate
- ZOJ 2966 Build The Electric System 最小生成树 Kruscal && Prim
- SOAPUI 断言之三
- js选择checkbox值,组织成key-value形式,传值到后台
- MySQL SubQuery学习记录
- js选择checkbox值,组织成key-value形式,传值到后台
- play framework框架进Debug,右键项目build path 空白(no actions available)等解决问题
- 【iOS官方文档翻译】UICollectionView与UICollectionViewFlowLayout