Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UITableView中的节索引标题之间添加填充(或增加高度)_Ios_Objective C_Uitableview_Height_Padding - Fatal编程技术网

Ios 在UITableView中的节索引标题之间添加填充(或增加高度)

Ios 在UITableView中的节索引标题之间添加填充(或增加高度),ios,objective-c,uitableview,height,padding,Ios,Objective C,Uitableview,Height,Padding,我已经通过方法sectionIndexTitlesForTableView:和sectionForSectionIndexTitle:为我的UITableView实现了一个节索引。我只有几个部分,默认情况下,它们在屏幕上垂直居中,每个索引标题之间的空间很小。我在其他应用程序中也看到过,它们增加了索引之间的空间,虽然不是很明显,但至少增加了几个点,让它们有喘息的空间,并在用户尝试点击他们想要的一个时提高了准确性。我想知道我如何才能做到这一点 这正是我想要得到的-请注意右侧索引之间的额外空间: 您可

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

这正是我想要得到的-请注意右侧索引之间的额外空间:


您可以做的是添加本文建议的额外空格

首先,让我们用伪索引创建一个数组



希望能有所帮助。

谢谢,这正是我想要的。很好的技巧-没有想到添加空字符串索引。这个问题与我在谷歌搜索后发现的截图一模一样——具有讽刺意味。
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:@""];
}
- (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;
}