zoukankan      html  css  js  c++  java
  • 获取UITableViewCell中UITextField的值方法总结

    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;  
        }  
    }  

    转自 http://blog.csdn.net/favormm/article/details/7380160

     
  • 相关阅读:
    [HTML]安卓下<video>无法点击播放
    [JSP]解决Maven创建项目失败
    [JSP]Maven+SSM框架(Spring+SpringMVC+MyBatis)
    [转]Express入门教程:一个简单的博客
    [转][译]关于CSS中的float和position和z-index
    [CSS]多浏览器兼容的垂直居中,兼容多个IE
    [转]非常实用的15款开源PHP类库
    [PHP]使用PHPMailer发送带附件并支持HTML内容的邮件
    ROS中阶笔记(一):机器人系统设计—ROS系统下连接外部传感器
    ROS入门笔记(十三):分布式通信
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2847387.html
Copyright © 2011-2022 走看看