gpt4 book ai didi

ios - 在 UITableView 中的部分索引标题之间添加填充(或增加高度)

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:41 25 4
gpt4 key购买 nike

我已经通过方法 sectionIndexTitlesForTableView:sectionForSectionIndexTitle: 为我的 UITableView 实现了一个部分索引。我只有几个部分,默认情况下它们在屏幕上垂直居中,每个索引标题之间的空间很小。我在其他应用程序中看到它们增加了索引之间的空间量,虽然不是很大,但至少增加了几个点以给它们一些喘息的空间,并在用户尝试点击他们想要的那个时提高准确性。我想知道如何才能做到这一点?

这正是我想要获得的——注意右边索引之间的额外空间:

enter image description here

最佳答案

您可以做的是添加此 answer 中建议的额外空格.

First, let's create an array with the fake index.

NSArray *array = self.mydataArray; // here are your true index
self.sectionsTitle = [NSMutableArray array];
int n = array.count;

// In IOS 7 all index of the items are clumped together in the middle,
// making the items difficult to tap.
// As workaround we added "fake" sections index
// reference: https://stackoverflow.com/questions/18923729/uitableview-section-index-spacing-on-ios-7

for (int i = 0; i < n; i++){
[self.sectionsTitle addObject:array[i]];
[self.sectionsTitle addObject:@""];
}

Then, you can implement tableview delegate methods with the following approach:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
// In IOS 7 all index of the items are clumped together in the middle,
// making the items difficult to tap.
// As workaround we added "fake" sections index
// reference: https://stackoverflow.com/questions/18923729/uitableview-section-index-spacing-on-ios-7
if ([sectionsTitle[section] isEqualToString:@""]){
return 0;
}
return x; // return your desire section height
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// In IOS 7 all index of the items are clumped together in the middle,
// making the items difficult to tap.
// As workaround we added "fake" sections index
// reference: https://stackoverflow.com/questions/18923729/uitableview-section-index-spacing-on-ios-7
if ([sectionsTitle[section] isEqualToString:@""]){
return nil;
}else{
// return your desire header view here,
// if you are using the default section header view,
// you don't need to implement this method
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return self.sectionsTitle;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
// In IOS 7 all index of the items are clumped together in the middle,
// making the items difficult to tap.
// As workaround we added "fake" sections index
// reference: https://stackoverflow.com/questions/18923729/uitableview-section-index-spacing-on-ios-7
if ([title isEqualToString:@""]){
return -1;
}
return [sectionsTitle indexOfObject:title];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// In IOS 7 all index of the items are clumped together in the middle,
// making the items difficult to tap.
// As workaround we added "fake" sections index
// reference: https://stackoverflow.com/questions/18923729/uitableview-section-index-spacing-on-ios-7
if ([sectionsTitle[section] isEqualToString:@""]){
return 0;
}
return // your logic here;
}


希望对您有所帮助。

关于ios - 在 UITableView 中的部分索引标题之间添加填充(或增加高度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23453112/

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