删除灰色UITableView索引栏

Gle*_*ith 4 objective-c scrollbar hide uitableview

我正在使用UITableView创建一个具有几个部分(2)的应用程序,当我运行时,表视图侧面有这个恼人的灰色索引栏,就像"iPod"应用程序中的那个,只有2个选项在里面.我的问题是,如何隐藏"索引栏",因为这是不必要的空间浪费?

示例:http:
//img824.imageshack.us/img824/7278/grayscrollbar.png

代码片段:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

(记住我的奇怪评论......)

HiGuy

小智 15

我试过这个,但它对我不起作用.所以我浏览了表视图属性,并得到了这个.

self.tableView.showsVerticalScrollIndicator = NO;
Run Code Online (Sandbox Code Playgroud)

奇迹般有效.

*对于任何想要在未来这样做的人.

  • 不起作用.它删除滚动条,而不是索引栏 (2认同)

Jos*_*erg 14

那个"滚动条"是你的索引栏,假设你在谈论巨大的灰色事物.

从sectionIndexTitlesForTableView返回nil,它会消失.