删除灰色的UITableView索引栏 [英] Remove Gray UITableView Index Bar

查看:106
本文介绍了删除灰色的UITableView索引栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有几个部分(2)的UITableView制作一个应用程序,当我运行时,表视图的侧面有这个烦人的灰色索引栏,就像"iPod"应用程序中的那个一样,但其中有2个选项.我的问题是,由于这是不必要的空间浪费,我该如何隐藏索引栏"?

I am making an application with a UITableView that has a few sections (2), and when I run, the table view has this annoying gray index bar on the side, like the one in the "iPod" application, that has but 2 options in it. My question is, how do I hide the "index bar," because it is an unnecessary waste of space?

示例:

代码段:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [sections count];
}

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

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 2;
    }
    return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [sections objectAtIndex:section];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.
    cell.textLabel.text = [content objectAtIndex:(indexPath.row + [[sectionAmounts objectAtIndex:indexPath.section] intValue])];
    tableView.showsVerticalScrollIndicator = NO;
    return cell;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    content = [NSArray arrayWithObjects:@"Sphere", @"Cylinder", @"Circle", nil];
    sections = [NSArray arrayWithObjects:@"3d", @"2d", nil];
    sectionAmounts = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:2], nil]; //Second number is objects in first section... odd huh?
    self.tableView.showsVerticalScrollIndicator = NO;
    [content retain];
    [sections retain];
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

(介意我的奇怪评论...)

(Mind my odd comments...)

HiGuy

推荐答案

假设您正在谈论的是灰色的东西,那么滚动条"就是您的索引条.

That "scroll bar" is your index bar, assuming you're talking about the giant grey thing.

从sectionIndexTitlesForTableView中返回nil,它将消失.

Return nil from sectionIndexTitlesForTableView: and it'll go away.

这篇关于删除灰色的UITableView索引栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆