zoukankan      html  css  js  c++  java
  • UITextField in a UITableViewCell

    http://stackoverflow.com/questions/409259/having-a-uitextfield-in-a-uitableviewcell

    http://stackoverflow.com/questions/7034433/how-to-get-uitextfield-values-when-button-is-clicked

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [self.tableLogin dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:CellIdentifier] autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
            if ([indexPath section] == 0) {
                UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 165, 30)];
                textfield.adjustsFontSizeToFitWidth = YES;
                textfield.textColor = [UIColor blackColor];
                textfield.backgroundColor = [UIColor whiteColor];
                textfield.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
                textfield.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
                textfield.textAlignment = UITextAlignmentLeft;
                textfield.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
                textfield.delegate = self;
    
                if ([indexPath row] == 0) {
                    textfield.tag = 0;
                    textfield.placeholder = @"your username";
                    textfield.keyboardType = UIKeyboardTypeDefault;
                    textfield.returnKeyType = UIReturnKeyNext;
                }
                else {
                    textfield.tag = 1;
                    textfield.placeholder = @"required";
                    textfield.keyboardType = UIKeyboardTypeDefault;
                    textfield.returnKeyType = UIReturnKeyDone;
                    textfield.secureTextEntry = YES;
                }
    
                [textfield setEnabled:YES];
                [cell addSubview:textfield];
                [textfield release];
            }
        }
        if ([indexPath section] == 0) { // Email & Password Section
            if ([indexPath row] == 0) { // Email
                cell.textLabel.text = @"Email";
            }
            else {
                cell.textLabel.text = @"Password";
            }
        }
        else { // Login button section
            cell.textLabel.text = @"Log in";
        }
    
        return cell;    
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        switch (textField.tag) {
            case 0:
                self.username = textField.text;
                break;
            case 1:
                self.password = textField.text;
                break;
        }
        return true;
    }
  • 相关阅读:
    私活。
    sql server 模拟数组【转】
    Updlock 与 Holdlock
    连上交换机后电脑无法上网
    linux的发展
    MySQL5.7中,用root用户登陆不进去数据库,报以下错误,然后重新修改了密码,好了。
    nginx反响代理tomcat配置ssl
    tomcat日志的切割脚本
    重启nginx报错:[error] invalid PID number "" in "/application/nginx-1.13.3/logs/nginx.pid"
    数据盘的挂载
  • 原文地址:https://www.cnblogs.com/eshizhan/p/3178436.html
Copyright © 2011-2022 走看看