3

押すとテーブルビューセクションが追加され、そのセクションに新しい行も追加されるボタンがあります。これをプログラムで実装するにはどうすればよいですか?

私はセルの配列を持っています。

これが私のコードです

- (IBAction)addCell:(id)sender {

    UITableViewCell *newCell = [[UITableViewCell alloc] init];

    counter++;
    [cells addObject:newCell];

    [self.tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [cells count];
}

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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      //this is where i want to adjust the row per section
      //this code hide the recent sections, only the current created section appears
      return [cells objectAtIndex:indexPath.row];
}
4

3 に答える 3

1

こんにちは、これを読んでみてください:

プログラムでUITableViewを表示するには?

プログラムで UITableView にセルを追加する


これがあなたを助けることを願っています。

于 2012-04-02T03:24:05.267 に答える