グーグルで調べてみましたが、これに関する直接的なチュートリアルや回答が見つからなかったので、質問することにしました。
を使用してグループ uitableview に新しい行を挿入できることを理解していinsertRowsAtIndexPath:withRowAnimation
ます。
私が今やりたいことは、新しい行を挿入するのではなく、各セクションに 2 つの行を含む新しいセクションを挿入したいということです。
どうすればこれを行うことができますか、または何を調べる必要がありますか?
私が試したこと:
NSMutableArray self.objectArray
。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.objectArray.count;
}
ではtableView:cellForRowAtIndexPath
、次のようにしました。
UITextField *itemNameTextField = (UITextField *)[cell viewWithTag:100];
NSString *itemName = self.objectArray[indexPath.section][@"itemName"];
[itemNameTextField setText:itemName];
[itemNameTextField addTarget:self action:@selector(updateItemName:) forControlEvents:UIControlEventEditingChanged];
addItemBarBtnTapped:
タップすると呼び出されるバーボタンアイテムがあります。
- (IBAction)addItemBarBtnTapped:(id)sender
{
// Create item object.
NSMutableDictionary *itemObject = [[NSMutableDictionary alloc] init];
itemObject[@"itemName"] = [NSString stringWithFormat:@"Item %d", self.billItemsArray.count+1];
itemObject[@"itemPrice"] = @"0";
itemObject[@"itemSharersArray"] = [[NSMutableArray alloc] init];
// Add itemObject to objectArray, which reflects the new number of sections, and reloadData to reflect changes.
[self.objectArray addObject:itemObject];
[self.tableView reloadData];
}
これは私が現在行っていることであり、アイテム 1、アイテム 2 などの正しい値を持つセルの textFields の値が表示されるため、機能します (これらの値は設定され、addItemBarBtnTapped
.
ただし、これは「tableView にセクションを追加する」正しい方法ではないと思います。「アニメーション」がありません。セクションを追加するたびに、セクションごとに 2 行を追加したいと考えています。
私の問題に関する回答が見つかりませんし、インターネット上にセクションを追加するためのチュートリアルもありません。皆さんの助けに本当に感謝しています!
ありがとう!