如何将嵌套行与单元格下方的表格单元格插入表格视图?

时间:2016-05-17 18:40:01

标签: ios objective-c iphone uitableview ipad

我是iPhone应用程序开发的新手。如果用户点击联系人部分中的第二行按钮并且根据数组将新单元格插入到行3-5中,并且他们稍后单击范围部分中的第一行按钮,则根据数组在行2-4中添加新单元格,那么之前的3-5个单元格现在将在第6-8行。

我完全很难理解如何编写插入行的代码。

enter image description here

这里.m文件的控制器:

      //#import <UIKit/UIKit.h>
      //#import "GeneralTableCell.h"
     @interface GeneralDetailViewController ()           <UITableViewDelegate,UITableViewDataSource>
   {
   NSMutableArray *arrays,*arrayName,*arrayNames;
    NSString *sectionName;
   GeneralTableCell  *cell;
  }
  @end

  @implementation GeneralDetailViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.tableViews.dataSource=self;
self.tableViews.delegate=self;

arrays = [[NSMutableArray alloc] initWithObjects:@"Scope",@"Contacts",nil];
arrayName = [[NSMutableArray alloc ] initWithObjects:@"Project Member     Report",@"Venders", nil];
arrayNames = [[NSMutableArray alloc ] initWithObjects:@"Scope Summary Report", nil];
 }

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

 -(IBAction)tapTOBack:(id)sender{

[self.navigationController popViewControllerAnimated:YES];
 }
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:    (NSInteger)section
 //{
 //    return 45;
 //}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:  (NSInteger)section
 {
 switch (section)
 {
    case 0:
        sectionName = NSLocalizedString(@"Scope", @"Scope");

        break;
    case 1:
        sectionName = NSLocalizedString(@"Contacts", @"Contacts");
        break;
    default:
        sectionName = @"";
        break;
 }
 return sectionName;
 }
 -(NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
 return arrays.count; 
 }

 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section{
 NSInteger Number;
 if ([sectionName isEqualToString:@"Scope"]) {

   Number=  [arrayNames count];
    NSLog(@"%ld",(long)Number);
     return  Number;
 }
else
   return [arrayName count];
//    return 2;
 }

  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=@"GeneralTableCell"; 
cell =[tableView dequeueReusableCellWithIdentifier:identifier   forIndexPath:indexPath];
if (cell == nil) {
    cell = [[GeneralTableCell alloc] initWithStyle:UITableViewCellStyleValue1
                                   reuseIdentifier:identifier];
}
cell.btnExpandble.tag = indexPath.row;
cell.lblRowName.text= [arrayName objectAtIndex:indexPath.row];
if (indexPath.section ==0) {
    cell.lblRowName.text=[arrayNames objectAtIndex:indexPath.row];
    cell.btnExpandble.tag=0;
}
else if (indexPath.section ==1){
     cell.lblRowName.text=[arrayName objectAtIndex:indexPath.row];
    if (indexPath.row ==0) {
        cell.btnExpandble.tag=1;
        [cell.btnExpandble addTarget:self action:@selector(tapToExpandCell:) forControlEvents:UIControlEventTouchUpInside];
    }
 } 
 return cell;
 }
 -(void)tapToExpandCell:(id)sender{

 }
 @end

0 个答案:

没有答案