0

我有UITableView2 个部分。在我的第一部分,有 5 行。在第二部分有 2 行。当我单击添加按钮时,必须一次又一次地复制此表视图。我怎样才能做到这一点?

-(IBAction)addDetails:(id)sender
{

    NSLog(@"value of s is %d,%d",s,210+100*s);

    tvc = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    tvc.tableView.frame = CGRectMake(20,200+250*s,280,280);
    //CGRect rect = CGRectMake(cell.bounds.origin.x+10, cell.bounds.origin.y+10,50,30);   
    [tvc.tableView setSectionFooterHeight:3.0];
    [tvc.tableView setSectionHeaderHeight:3.0];

    [tvc.tableView setShowsVerticalScrollIndicator:YES];
    // [tvc.tableView setBackgroundColor:[UIColor  colorWithRed:67.0/255.0 green:185.0/255.0 blue:209.0/255.0 alpha:0.5]];
    [tvc.tableView setRowHeight:30];
    tvc.tableView.backgroundView = nil;
    tvc.tableView.backgroundColor = [UIColor clearColor];
    [tvc.tableView setSeparatorStyle:UITableViewCellSelectionStyleGray];
    tvc.tableView.delegate = self;
    tvc.tableView.dataSource = self;
    [self.view addSubview:tvc.tableView];
   s++;

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

      if(section == DETAIL_SECTION)
          return 5;
      else if(section == CALENDER_SECTION){
          return 2;
      }


}


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

当再次调用 addDetails 函数时,我希望在同一框架内具有不同数据的相同表结构。现在框架正在重复。请帮我解决这个问题

4

1 回答 1

0

当您单击添加按钮时,创建一个新UITableView实例,将其作为子视图添加到现有视图中。根据您的需要定位和调整大小。将其委托和数据源设置为与原始委托和数据源相同的委托和数据源。这样,相同的委托/数据源方法将使用相同的逻辑作用于每个表。每当您重新加载原始表时,请务必重新加载所有“复制”表。

于 2013-02-08T14:47:21.593 回答