2013-03-11 56 views
1

我有2个的UITextField的和一个按钮,当我点击按钮填补这些我得UItextfields和按钮的tableview细胞具有相同的格式,当我填写这些并单击按钮必须添加后相同的文本字段到下一个单元格保持上述单元格相同,并且文本字段中的数据不会被删除增加细胞动态地UITableView中,当点击按钮

Iam新编程时我不知道如何在单击按钮时将视图添加到单元格 帮我解决这个问题。

-(IBAction)btnaddbusiness:(UIButton*)sender 
{ 
    tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 370, 300, 30)]; 

    tableView.delegate=self; 
    tableView.dataSource=self; 
    [testscroll addSubview:tableView]; 
     i=i+1; 
    if(sender.tag==1 || i==1) 
    { 

     if([txtprovEmail1.text isEqualToString:@""] && [txtprovName1.text isEqualToString:@""]) 
     { 

     } 
     else 
     { 
      testscroll.contentSize=CGSizeMake(320, 500); 
      view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 30)]; 

      txtprovName2 =[[UITextField alloc]init]; 
      [txtprovName2 setFrame:CGRectMake(0,0,116, 30)]; 
      [txtprovName2 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovName2 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovName2.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Name"; 
      txtprovName2.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovName2.userInteractionEnabled=YES; 
      [view1 addSubview:txtprovName2]; 

      txtprovEmail2 =[[UITextField alloc]init]; 
      [txtprovEmail2 setFrame:CGRectMake(130, 0,116, 30)]; 
      [txtprovEmail2 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovEmail2 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovEmail2.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Email"; 
      txtprovEmail2.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovEmail2.userInteractionEnabled=YES; 
      [view1 addSubview:txtprovEmail2]; 

      btnRemove1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      btnRemove1.frame = CGRectMake(268, 0,80, 30); 
      [btnRemove1 setTitle:@"Remove" forState:UIControlStateNormal]; 
      [btnRemove1.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]]; 
      // [ btnRemove1 setBackgroundImage:[UIImage imageNamed:@"background-button.png"] forState:UIControlStateNormal]; 
      btnRemove1.titleLabel.textColor=[UIColor blackColor]; 
      btnRemove1.tag=1; 

      // [btnRemove1 addTarget:self action:@selector(btnRemove1Clicked)    forControlEvents:UIControlEventTouchUpInside]; 
      [ view1 addSubview: btnRemove1]; 

      /* btnsubmit = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      btnsubmit.frame = CGRectMake(40, 470,80, 30); 
      [btnsubmit setTitle:@"Submit" forState:UIControlStateNormal]; 
      [btnsubmit.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]]; 

      btnsubmit.titleLabel.textColor=[UIColor blackColor]; 

      [btnsubmit addTarget:self 
          action:@selector(btnsubmitclicked) 
       forControlEvents:UIControlEventTouchUpInside]; 
      [ testscroll addSubview: btnsubmit];*/ 



      /* 
      btnreset = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      btnreset.frame = CGRectMake(100, 470,80, 30); 
      [btnreset setTitle:@"Reset" forState:UIControlStateNormal]; 
      [btnreset.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]]; 

      btnreset.titleLabel.textColor=[UIColor blackColor]; 

      [btnreset addTarget:self 
         action:@selector(btnResetclicked) 
       forControlEvents:UIControlEventTouchUpInside]; 
      [ testscroll addSubview: btnreset]; 




      */ 



      sender.tag=2; 

     } 
    } 

    else if(sender.tag==2|| i==2) 
    { 

     if(txtprovEmail2.text==NULL && txtprovName2.text==NULL) 
     { 

     } 
     else 
     { 

      testscroll.contentSize=CGSizeMake(320, 600); 
      testscroll.pagingEnabled=YES; 
      view2=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 30)]; 
      txtprovName3 =[[UITextField alloc]init]; 
      [txtprovName3 setFrame:CGRectMake(20, 470,94, 30)]; 
      [txtprovName3 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovName3 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovName3.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Name"; 
      txtprovName3.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovName3.userInteractionEnabled=YES; 
      [view2 addSubview:txtprovName3]; 

      txtprovEmail3 =[[UITextField alloc]init]; 
      [txtprovEmail3 setFrame:CGRectMake(118, 470,92, 30)]; 
      [txtprovEmail3 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovEmail3 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovEmail3.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Email"; 
      txtprovEmail3.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovEmail3.userInteractionEnabled=YES; 

      [view2 addSubview:txtprovEmail3]; 

      btnRemove2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      btnRemove2.frame=CGRectMake(210, 470, 80, 30) ; 
      [btnRemove2 setTitle:@"Remove" forState:UIControlStateNormal]; 
      [btnRemove2.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]]; 
      // [ btnRemove1 setBackgroundImage:[UIImage imageNamed:@"background-button.png"] forState:UIControlStateNormal]; 
      btnRemove2.titleLabel.textColor=[UIColor blackColor]; 

      /* [btnRemove2 addTarget:self action:@selector(btnRemove2Clicked) 
       forControlEvents:UIControlEventTouchUpInside];*/ 
      btnRemove2.tag=2; 
      [view2 addSubview:btnRemove2]; 

      [btnreset removeFromSuperview]; 
      [btnsubmit removeFromSuperview]; 


      [ btnsubmit setFrame:CGRectMake(80, 510, 50, 30)]; 
      [btnreset setFrame:CGRectMake(80, 510, 50, 30)]; 

      sender.tag=3; 

     } 
    } 

    else if(sender.tag==3 || i==3) 
    { 

     if(txtprovEmail3.text==NULL && txtprovName3.text==NULL) 
     { 

     } 
     else 
     { 

      testscroll.contentSize=CGSizeMake(320, 700); 

      txtprovName4 =[[UITextField alloc]init]; 
      [txtprovName4 setFrame:CGRectMake(20, 510,94, 30)]; 
      [txtprovName4 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovName4 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovName4.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Name"; 
      txtprovName4.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovName4.userInteractionEnabled=YES; 
      [testscroll addSubview:txtprovName4]; 

      txtprovEmail4 =[[UITextField alloc]init]; 
      [txtprovEmail4 setFrame:CGRectMake(118, 510,92, 30)]; 
      [txtprovEmail4 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovEmail4 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovEmail4.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Email"; 
      txtprovEmail4.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovEmail4.userInteractionEnabled=YES; 

      [testscroll addSubview:txtprovEmail4]; 

      btnRemove3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      btnRemove3.frame = CGRectMake(210, 510,80, 30); 
      [btnRemove3 setTitle:@"Remove" forState:UIControlStateNormal]; 
      [btnRemove3.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]]; 
      // [ btnRemove1 setBackgroundImage:[UIImage imageNamed:@"background-button.png"] forState:UIControlStateNormal]; 
      btnRemove3.titleLabel.textColor=[UIColor blackColor]; 

      [btnRemove3 addTarget:self action:@selector(btnRemove3Clicked) 
       forControlEvents:UIControlEventTouchUpInside]; 
      btnRemove3.tag=3; 
      [testscroll addSubview:btnRemove3]; 

      [btnreset removeFromSuperview]; 
      [btnsubmit removeFromSuperview]; 

      [ btnsubmit setFrame:CGRectMake(40, 550, 50, 30)]; 
      [btnreset setFrame:CGRectMake(100, 550, 50, 30)]; 
      sender.tag=4; 

     } 
    } 
    else if(sender.tag==4||i==4) 
    { 

     if(txtprovEmail4.text==NULL && txtprovName4.text==NULL) 
     { 

     } 
     else 
     { testscroll.contentSize=CGSizeMake(320, 800); 
      txtprovName5 =[[UITextField alloc]init]; 
      [txtprovName5 setFrame:CGRectMake(20, 550,94, 30)]; 
      [txtprovName5 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovName5 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovName5.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Name"; 
      txtprovName5.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovName5.userInteractionEnabled=YES; 
      [testscroll addSubview:txtprovName5]; 

      txtprovEmail5 =[[UITextField alloc]init]; 
      [txtprovEmail5 setFrame:CGRectMake(118, 550,92, 30)]; 
      [txtprovEmail5 setBorderStyle:UITextBorderStyleRoundedRect]; 
      [txtprovEmail5 setAutocorrectionType:UITextAutocorrectionTypeNo]; 
      txtprovEmail5.textAlignment=UITextAlignmentCenter; 
      [email protected]"Provider Email"; 
      txtprovEmail5.font=[UIFont fontWithName:@"System" size:11]; 
      txtprovEmail5.userInteractionEnabled=YES; 

      [testscroll addSubview:txtprovEmail5]; 

      btnRemove4 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      btnRemove4.frame = CGRectMake(210, 550,80, 30); 
      [btnRemove4 setTitle:@"Remove" forState:UIControlStateNormal]; 
      [btnRemove4.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]]; 
      // [ btnRemove1 setBackgroundImage:[UIImage imageNamed:@"background-button.png"] forState:UIControlStateNormal]; 
      btnRemove4.titleLabel.textColor=[UIColor blackColor]; 

      [btnRemove4 addTarget:self action:@selector(btnRemove4Clicked) 
       forControlEvents:UIControlEventTouchUpInside]; 
      btnRemove4.tag=4; 
      [testscroll addSubview:btnRemove4]; 
      testscroll.scrollEnabled=YES; 


      [btnreset removeFromSuperview]; 
      [btnsubmit removeFromSuperview]; 

      [ btnsubmit setFrame:CGRectMake(40, 690, 50, 30)]; 
      [btnreset setFrame:CGRectMake(100, 690, 50, 30)]; 



     } 
    } 
} 
+0

尝试搜索自定义的uitableviewcell https://www.google.co.in/search?q=custom+table+view+ios&aq=2&oq=custom+tab&aqs=chrome.3.57j0l3j60l2.6698&sourceid=chrome&ie=UTF-8 #HL = EN&sclient = PSY-AB&q =定制+的UITableViewCell +的UITextField&OQ =定制+的UITableViewCell +的UITextField&gs_l = serp.1.0.0.7155.11239.3.12222.11.6.1.4.4.0.118.577.4j2.6.0.les%3B..0.0 .. .1c.1.5.psy-ab.KFxGmYGQ-84&pbx = 1&bav = on.2,or.r_qf。&bvm = bv.43287494,d.bmk&fp = 1fc7e9b832ceaa6b&biw = 982&bih = 581 – 2013-03-11 06:47:51

+0

单击addbutton时,我想添加另一个视图tableviewcell这样我怎么能动态地添加使用标记的细胞 – Sindu 2013-03-11 06:51:35

+0

您可以添加您的视图,并保持它隐藏在一开始,当按钮被点击刷新你的表,并根据条件设置隐藏假。 – 2013-03-11 06:52:47

回答

0

您可以从here

以下链接下载示例应用程序也将帮助你。

UITextField in UITableViewCell Help

How to put a UITextField inside of a UITableViewCell (grouped)?

编辑:

你只需要重载[tablename reloadData];)您在-(IBAction)btnaddbusiness:(UIButton*)sender表。

你正在做的添加视图应该在rowForIndexPath:

你所能做的就是在你的函数设置一个变量布尔TRUE重装你的表,并在rowForIndexPath,检查是否变量是然后设置乌尔鉴于隐藏财产到,反之亦然。

+0

我怎样才能将其添加于各种行的单元格的列,您可以创建** ** txtprovName2在** ** rowForIndexPath和像'[cell.contentView addSubview:txtprovName2];'一样添加到你的行中 – Sindu 2013-03-11 07:26:51

+0

添加到表视图我怎样才能 – 2013-03-11 07:31:35