获取UITableView每行中不同的UITextField输入的内容(例如修改登陆密码)
2015-06-27 17:46
501 查看
@interface AZTPasswordModifyViewController ()<UITableViewDelegate, UITableViewDataSource>{
NSString *_theOldPassword ;
NSString *_theNewPassword;
NSString *_theTwiceNewPassword;
}
- (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;
}
}
NSString *_theOldPassword ;
NSString *_theNewPassword;
NSString *_theTwiceNewPassword;
}
- (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;
}
}
相关文章推荐
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树+二分
- CSS3系列四(Media Queries移动设备样式)
- setContentView剖析
- UILabel属性使用
- Android UI 之 ProgressBar、ProgressDialog、AlertDialog
- Android UI 之 ProgressBar、ProgressDialog、AlertDialog
- valueForKeyPath 方法的使用
- PowerBuilder9.0自动检测注册ASA8.0
- 下载:Windows 10 Build 10154默认新壁纸
- Builder模式在Java中的应用(转)
- UIImageView
- UIButton 导航栏属性
- UIView的layoutSubviews和drawRect方法何时调用
- 如何自己编写一个easyui插件续
- UIImageView UIButton之间的区别
- xcode7 UI 测试
- 求出最长非降子序列的长度--LIS:longest increasing subsequence
- UIView的属性方法解释(全)
- iOS开发之使用UIView-Positioning简化页面布局
- 【后缀自动机】 CodeForces 235C Cyclical Quest