gpt4 book ai didi

ios - 动态添加部分到 UITableView,然后动态添加子单元格到特定部分。

转载 作者:行者123 更新时间:2023-11-29 01:48:44 25 4
gpt4 key购买 nike

我是编程新手,很抱歉没有使用正确的术语。

尝试创建一个 TableView ,用户可以在其中创建新的部分,然后动态地将子单元格添加到特定部分(部分标题将包含一个“添加”按钮来添加这些单元格。类似于待办事项列表功能带有子项。

我会为部分中的按钮使用“发件人”或“标签”,以便它们不会将单元格添加到其他部分。或者,(通俗地说)按钮如何知道单元格将仅添加到该部分。

我一直在研究,发现的所有内容都是针对预定义数组的。因此,如果有人能指出正确的方向,我将不胜感激。

最佳答案

#pragma mark - Tableview Delegate



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{
//number of section to add in tableview
return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return //number of row you want to add in particular section ;

}

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

{

NSString *CellIdentifier = [NSString stringWithFormat:@"cell %ld",(long)indexPath.row];



UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];



cell = nil;



if (cell == nil)

{

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];







cell.textLabel.text = //set data to cell which you want ;



cell.backgroundColor = [UIColor clearColor];





}



return cell;

}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

{
//perform action after clicking on particular cell of tableview


}

关于ios - 动态添加部分到 UITableView,然后动态添加子单元格到特定部分。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31644600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com