自定义索引部分列表定位

时间:2012-07-20 21:11:45

标签: ios uitableview indexing

我通过使用循环以编程方式添加按钮来实现自定义索引节列表。这是我的表视图控制器中的代码:

int offset = 65;
int yposition = 40;
NSString *letter;
for (int i=0; i<26; i++) 
{
    letter = [NSString stringWithFormat:@"%c",offset];
    UIButton *a = [UIButton buttonWithType:UIButtonTypeCustom];
    [a setAlpha:0.7];
    a.frame = CGRectMake(300,yposition,20,15);
    [a setTitle:letter forState:UIControlStateNormal];
    [a addTarget:self action:@selector(pressedIndex:) forControlEvents:UIControlEventTouchUpInside];
    [self.parentViewController.view addSubview:a];
    offset += 1;
    yposition += 15;
}

它工作正常,除非我回到父视图,索引列表仍然存在。这是有道理的。如果我直接在表格视图中按下索引列表按钮,那么当用户向下滚动表格视图时,按钮会向下滚动并消失。

关于如何让我的按钮位置保持在屏幕上的任何建议?

谢谢。

1 个答案:

答案 0 :(得分:0)

我最终使用了一个nib文件,在IB中添加了一个视图,并以编程方式将我的索引列表按钮添加到该视图中。

相关问题