iOS之获取UITableViewCell中UITextField的值
来源:互联网 发布:电脑解除限制软件 编辑:程序博客网 时间:2024/05/18 21:11
UITableViewCell的contentView中的UITextField的值获取有几种方法,本人简单总结一下。
1. 获取UITextField所以Cell的NSIndexPath,知道了NSIndexPath就知道了这个UITextField是干什么的了。
可以在
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
- {
- //get cell
- UITableViewCell *cell = [UITableViewCell ][[textField superview] superview];
- NSIndexPath *indexPath = [tableView indexPathForCell:cell];
- }
或
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
- //get cell
- UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
- NSIndexPath *indexPath = [tableView indexPathForCell:cell];
- }
中得知道UITextField中text是哪一个数据结构的值,前一个是实时的,后一个是失去焦点时一次性的。
2。第二种方法与上面第一个有点类似也是实时的,来自:http://blog.sina.com.cn/s/blog_9ca91e4a0100xlvu.html
- - (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;
- }
- }
阅读全文
0 0
- iOS之获取UITableViewCell中UITextField的值方法总结
- iOS之获取UITableViewCell中UITextField的值
- iOS之获取UITableViewCell中UITextField的关联方法
- iOS之获取UITableViewCell中UITextField的值方法总结(二)
- 获取UITableViewCell中UITextField的值方法总结
- UITableViewCell的contentView中的UITextField的值获取的方法
- iOS 实时监听UITableViewCell中的UItextField的值的变化
- iOS开发Debug之获取UITextField当前显示的内容
- iOS开发之UitableViewCell中UISwitch的使用,代理实现
- iOS中UITextField的使用
- ios中UITextField的使用
- 在UITableViewCell的UITextField中,点 return时,光标移到下一个UITextField
- IOS/UITextField 光标的位置设置获取
- IOS - 获取UITextField的输入文本
- iOS中如何通过点击UITableViewCell中的Button来获取当前Cell的indexPath
- iOS之UITableViewCell的重用机制
- iOS开发之有间距的UITableViewCell
- iOS开发之有间距的UITableViewCell
- MARK!! 博客记录第一篇
- windows系统下nginx+tomcat+redis做负载均衡和session粘滞附整套解决方案
- 网站页面底部的著作权(版权)声明应该怎么写?
- windows 显示程序被加载地址的三种方法
- 习题8.3--证明吝啬SAT是NP-完全问题
- iOS之获取UITableViewCell中UITextField的值
- POJ 2393 Yogurt factory 贪心
- Oracle逻辑备份脚本(收集学习)
- Android Snackbar使用详解
- eclipse用安卓模拟器遇到的一个问题
- 《IDEA 循环依赖》Annotation processing is not supported for module cycles.
- [Leetcode] 268. Missing Number 解题报告
- Opencv Sift算子特征提取与匹配
- 一只小蜜蜂