gpt4 book ai didi

iphone - 在 UITableView 中显示元素,就像 iPhone 联系人一样,分成按字母顺序排列的部分?

转载 作者:行者123 更新时间:2023-12-03 20:25:34 26 4
gpt4 key购买 nike

我一直在网上寻找解决方案,但似乎找不到任何东西,我陷入了困境。

我有一个 NSMutableArray:

productsToDisplay

它由一堆 Product 对象组成,每个对象都有一个“name”属性,例如

Product *product = ....

NSLog(@"%@", product.name);

每个单元格都会显示产品名称,单击后会显示有关该产品的更多信息。

但是,我有很多产品,并且希望将它们分成 UITableView 中的按字母顺序排列的部分(就像 iPhone 上的联系人一样)。

有人能指出我正确的方向吗?

非常感谢,

jack

[编辑]我意识到我可以只对 name 属性上的数组进行排序,但我还想要 UITableView 右侧的快速搜索栏,以便用户可以轻松找到他们正在查找的部分。

最佳答案

使用此委托(delegate)显示右侧部分列表:-

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return searchArray;
}

使用此委托(delegate)根据右侧列表关联表格内容(部分):-

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
if (index == 0) {
[tableView scrollRectToVisible:[[tableView tableHeaderView] bounds] animated:NO];
return -1;
}
return index;
}

关于iphone - 在 UITableView 中显示元素,就像 iPhone 联系人一样,分成按字母顺序排列的部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8981964/

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