2011-09-15 21 views
0

在我的Iphone应用程序中,我必须在tableview的两行添加文本框,并将复选框添加到一行。任何人都可以为我提供一个可以帮助我的例子。我是iPhone上的新手,我不知道如何从这开始。在桌面上添加文本框和复选框

在此先感谢..

+0

你应该学会对UITableView的第一个自定义单元格... – Maulik

+0

你尝试过什么?你是否通过编程或使用IB创建表? – Maulik

+0

我使用IB创建了表格..我试图添加一个文本框但没有任何反应 – Gabrielle

回答

0

按您的评论试试这个:

if(indexPath.row==1) 
{ 
    UITextField *labl=[[UITextField alloc] init]; 
    // where is your text field's frame ???? 
    labl.frame = CGRectMake(10,10,50,50); 
    [email protected]"data"; 
    [cell addSubview:labl]; 
} 
+0

没有任何反应 – Gabrielle

+0

检查更新的答案.. – Maulik

+0

请不要这样做。它可能工作,但这种方式添加的视图通常会在单元格转换进出编辑模式时不适当地定位,并且通常是很冒险的。 'UITableViewCell contentView'属性专门为将子视图添加到单元格而创建。 – memmons

1

嘿尝试在你的cellForRowAtIndexPath这一个

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]]; 
if (!cell){ 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]] autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
} 

if(indexPath.row == 0){ 
      // NSString *daytime = [[NSUserDefaults standardUserDefaults] objectForKey:@"day"]; 
      UITextField *text0 = [[UITextField alloc] initWithFrame:CGRectMake(20, 12, 120, 22)]; 
      text0.textAlignment = UITextAlignmentLeft; 
      text0.backgroundColor = [UIColor whiteColor]; 
      text0.borderStyle = UITextBorderStyleNone; 
      text0.userInteractionEnabled = FALSE; 
      text0.font = [UIFont boldSystemFontOfSize:17]; 
      text0.textColor = [UIColor blackColor]; 
      text0.delegate = self; 
      text0.text = @"Type de Parteneria"; 
      [cell addSubview:text0]; 

      UITextField *text1 = [[UITextField alloc] initWithFrame:CGRectMake(120, 12, 160, 20)]; 
      text1.textAlignment = UITextAlignmentRight; 
      text1.borderStyle = UITextBorderStyleNone; 
      text1.backgroundColor = [UIColor whiteColor]; 
      text1.userInteractionEnabled = TRUE; 
      text1.font = [UIFont boldSystemFontOfSize:16]; 
      text1.textColor = [UIColor colorWithRed:114.0f/255.0f green:136.0f/255.0f blue:165.0f/255.0f alpha:1.0]; 
      text1.delegate = self; 

      [cell addSubview:text1]; 

    } 
    else if(indexPath.row == 1){ 
      // NSString *daytime = [[NSUserDefaults standardUserDefaults] objectForKey:@"day"]; 
      UITextField *text0 = [[UITextField alloc] initWithFrame:CGRectMake(20, 12, 120, 22)]; 
      text0.textAlignment = UITextAlignmentLeft; 
      text0.backgroundColor = [UIColor whiteColor]; 
      text0.borderStyle = UITextBorderStyleNone; 
      text0.userInteractionEnabled = FALSE; 
      text0.font = [UIFont boldSystemFontOfSize:17]; 
      text0.textColor = [UIColor blackColor]; 
      text0.delegate = self; 
      text0.text = @"Audi R8"; 
      [cell addSubview:text0]; 


      UIButton *signBtn = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 
     signBtn.frame = CGRectMake(15, 170, 290, 35); 
     [signBtn setTitle:@"Sign Up" forState:UIControlStateNormal]; 
     [signBtn setBackgroundImage:[UIImage imageNamed:@"CheckBox.png"] forState:UIControlStateNormal]; 
     [signBtn setFont:[UIFont boldSystemFontOfSize:17]]; 
     [signBtn addTarget:self action:@selector(checkPressed) forControlEvents:UIControlEventTouchDown]; 
     [cell addSubview:signBtn]; 
    } 
    return cell; 

}

如果您得到的消息,我的问题

+1

我收到信号SIGABRT – Gabrielle

+0

哦!我的错误最后你必须写回单元格; – Hiren