2013-10-21 23 views
0

我正在制作一个iPhone应用程序,我希望当应用程序加载它时,应该只有一个单元格与文本字段时,用户在第一个单元格中输入任何数据它应该与输入数据的新单元格和第一个单元格应该是可编辑的空白。 我正在做,但它也显示在上面的单元格相同的值。如何插入UITextField顶部行iphone应用程序

enter image description here

这里是代码

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

    { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

    if (!cell) { 



    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 


    cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"tabelsales.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]; 
    cell.backgroundColor = [UIColor clearColor]; 

    } 



    if (indexPath.section==0) { 
    tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(13, 6, 250, 26)]; 
    tagInputField.tag = 2; 
    tagInputField.delegate = self; 
    tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing; 
    tagInputField.font=[UIFont fontWithName:@"Myriad-Pro" size:8]; 
    [tagInputField setText:@" "]; 

    tagInputField.textColor =[UIColor grayColor]; 

    [cell addSubview:tagInputField]; 

    [email protected]""; 

    return cell; 

    } 

    if (indexPath.section==1) { 
    UIButton *crossButton =[[UIButton alloc]initWithFrame:CGRectMake(230, 8, 18, 18)]; 
    //crossButton.backgroundColor = [UIColor purpleColor]; 
    crossButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Cross.png"]]; 
    [cell addSubview:crossButton]; 
    cell.textLabel.font =[UIFont systemFontOfSize:13]; 
    cell.textLabel.textColor =[UIColor grayColor]; 
    cell.textLabel.text =[tagArray objectAtIndex:indexPath.row]; 
    [crossButton addTarget:self action:@selector(deleteCell:) forControlEvents:UIControlEventTouchUpInside]; 

    return cell; 


    }   

    } 
+0

的问题是在你的代码。你需要分享你的代码。 –

+0

@SarwarErfan添加代码请检查 –

+0

尝试使用我发布的更新后的代码。让我知道它是否有效。 –

回答

0

试试这个代码:

-(UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if(!cell) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 
     cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"tabelsales.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]; 
     cell.backgroundColor = [UIColor clearColor]; 
    } 

    for (UIView *subView in cell.subviews) 
    { 
     if (subView.tag == 2 || subView.tag == 22) 
     { 
      [subView removeFromSuperview]; 
     } 
    } 


    if(indexPath.section==0){ 
     tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(13, 6, 250, 26)]; 
     tagInputField.tag = 2; 
     tagInputField.delegate = self; 
     tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing; 
     tagInputField.font=[UIFont fontWithName:@"Myriad-Pro" size:8]; 
     [tagInputField setText:@" "]; 
     tagInputField.textColor =[UIColor grayColor]; 
     [cell addSubview:tagInputField]; 
     [email protected]""; 
     return cell; 
    } 

    if(indexPath.section==1) { 
     UIButton *crossButton =[[UIButton alloc]initWithFrame:CGRectMake(230, 8, 18, 18)]; 
     *crossButton.tag = 22; //use a tag value that is not used for any other subview 
     //crossButton.backgroundColor = [UIColor purpleColor]; 
     crossButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Cross.png"]]; 
     [cell addSubview:crossButton]; 
     cell.textLabel.font =[UIFont systemFontOfSize:13]; 
     cell.textLabel.textColor =[UIColor grayColor]; 
     cell.textLabel.text =[tagArray objectAtIndex:indexPath.row]; 
     [crossButton addTarget:self action:@selector(deleteCell:) forControlEvents:UIControlEventTouchUpInside]; 
     return cell; 
    } 
} 
+0

这项工作,但我不想显示 - 此单元格 –

+0

您可以发布有关您正在谈论的标志的图像吗? –

相关问题