I’ve implemented a custom index section list by programmatically adding buttons using a loop. Here is the code in my table view controller:
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;
}
It works fine, except when I go back to the parent view, which the index list is still present on. And that makes sense. If I hard my index list buttons directly the table view, then when the user scrolls down the table view, the buttons scrolls down and disappear.
Any suggestion as to how I could have my buttons position persist on the screen?
Thank you.
I ended up using a nib file, adding a view in IB, and programmatically adding my index list buttons to that view.