zoukankan      html  css  js  c++  java
  • ios-给tableview Cell 添加不同的控件

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        
        _tableView  = [[UITableView alloc] initWithFrame: CGRectMake(10, 90, 300, 200) style: UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview: _tableView];
        
        
    }
    
    
    #pragma mark uitableview delegate
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 3;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *baseCell = @"base";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: baseCell];
        if(!cell)
        {
            cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: baseCell] autorelease];
        }
        
        if(2 == indexPath.row)
        {
            
            cell.textLabel.text = @"年龄: ";
            
            UITextField *tf = [[UITextField alloc] initWithFrame: CGRectMake(65.0, 5.0, 160.0, 35.0f)];
            tf.borderStyle = UITextBorderStyleRoundedRect;
            tf.delegate = self;
            tf.placeholder = @"输入年龄";
            tf.returnKeyType = UIReturnKeyDone;
            [cell.contentView addSubview: tf];
            
            return cell;
        }
        
        if(0 == indexPath.row)
        {
            cell.textLabel.text = @"1";
            
            return cell;
        }
        
        
        if(1 == indexPath.row)
        {
            cell.textLabel.text = @"2";
            
            return cell;
        }
        
        
        return cell;
    }
    
    #pragma mark UITextFieldDelegate
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        [textField resignFirstResponder];
        
        return YES;
    }
  • 相关阅读:
    启动hbase时出现HMaster Aborted错误
    kylin的安装与配置
    【转】HBase原理和设计
    ts项目报错:Import sources within a group must be alphabetized
    TypeScript 之 tsconfig.json
    TypeScript 之 声明文件的结构
    TypeScript 之 声明文件的使用
    TypeScript 之 声明文件的发布
    TypeScript 之 NPM包的类型
    create-react-app-typescript 知识点
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4763383.html
Copyright © 2011-2022 走看看