I’m programatically adding a button to a UITableViewController like this:
-(void)createFlipButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark];
button.frame = CGRectMake(282, 372, 18, 19);
[button addTarget:self action:@selector(flipView) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:button];
[self.view bringSubviewToFront:button];
}
But it’s getting stuck in the cell that occupies the button.frame space. why isn’t [self.view bringSubviewToFront:button] working?
Also, [self.tableView bringSubviewToFront:button] doesn’t work either.
I guess what you really want is a floating view, i.e. a view that doesn’t move when the table view scrolls. The reason the button looks sticky to your cell is that the whole table is in a scroll view, so when the content moves, the button does as well.
The way to go is to adjust the position of your added view when the table scrolls. Just implement the delegate method:
You will need to store a reference for your button, so that you can access it here, and maybe put the location of the button into an ivar as well.
If you have access to the WWDC 2011 Videos, you will find the trick there in Session 125.