UIButtons in UITableViewCell for ipad
I created UIButtons in UITableViewCell. It is displaying properly in iphone. But when I upgrade this app for iPad UIbuttons are shifted to right side and come out of the table's boundary . Here is my code
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setFrame:CGRectMake(47.0f, 100.0f, 16, 1开发者_开发问答6.0f)];
[button2 setImage:[UIImage imageNamed:@"Delete.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button2];
return cell;
You should probably add the button to the cell's contentView, and not to the cell directly.
You might also want to place the button's frame origin relative to the contentView's frame size, + set the button's autoresizing mask so that it is placed properly according to the cell size (which can change based on device type and/or interface orientation).
Please try this one. In you code remove [cell addSubview:button2]; add write there [cell.contentView addSubview:button2]; and also for removing overlapping of cell or for removing disturb buttons frame add this for loop before all cell content view allocated.
for(UIView *view in cell.contentView.subviews)
{
[view removeFromSuperview];
}
then you can add here uibuttons uilabels , etc...
精彩评论