2012-11-01 43 views

回答

0

这不是按钮上的文本框。实际上它是表格视图内的文本框。您必须执行以下操作:

  1. 以nib上的表格视图进行操作。
  2. 创建出口并设置委托和数据源。
  3. 然后将下面的代码添加到.m文件中。

尝试在此之前这个

设置行的表视图都有数。

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"]; 
    if(cell == nil) 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease]; 

    cell.textLabel.text = [[NSArray arrayWithObjects:@"First",@"Second",@"Third",@"Forth",@"Fifth",@"Sixth",@"Seventh",@"Eighth",@"Nineth",@"Tenth",nil] 
          objectAtIndex:indexPath.row]; 

    if (indexPath.row % 2) { 
     UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 21)]; 
     textField.placeholder = @"Enter Text"; 
     textField.text = [inputTexts objectAtIndex:indexPath.row/2]; 
     textField.tag = indexPath.row/2; 
     textField.delegate = self; 
     cell.accessoryView = textField; 
     [textField release]; 
    } else 
     cell.accessoryView = nil; 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell;   
} 

或者,你可以看到这个链接See this answer on SO

0

这是一个基本的分组UITableView。阅读Apple文档。这方面也有很多教程。

+0

这应该是一个评论 – NAZIK