gpt4 book ai didi

ios - UITableView 中的部分

转载 作者:行者123 更新时间:2023-11-29 03:04:41 25 4
gpt4 key购买 nike

几天来,我一直在努力研究如何将节标题添加到我的 UITableView,尽我所能进行研究,阅读它接缝了数百页,至少有人能给我指出正确的方向吗?

我有一个数组:

  recipes = [NSArray arrayWithObjects:recipe1, recipe2, recipe3, recipe4, nil];

这是来自以下 132 个的提要:

Recipe *recipe1 = [Recipe new];
recipe1.name = @"Almonds";
recipe1.image = @"almonds.jpg";

Recipe *recipe2 = [Recipe new];
recipe2.name = @"Apples";
recipe2.image = @"apples.jpg";

等等……

我正在寻找:

A
Almonds
Apples
B
Bananas
Blackcurrants...

共有 27 个部分。

最佳答案

如果你只想要节标题标题,你可以使用 UITableViewDataSource 方法:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

或者您可以使用 UITableViewDelegate 方法将自定义 View 设置为标题:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

实现这些的 Controller 需要成为 TableView 的委托(delegate)/数据源。

关于ios - UITableView 中的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22915864/

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