UITableViewCell contentView button disappears after changing orientation in iOS 6

 if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
 {
    //Landscape mode.
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  //Frame for iPad
    {
        [deleteButton setFrame:CGRectMake(984, 7, 30, 30)];
        [editButton setFrame:CGRectMake(944, 7, 30, 30)];
    }
    else
    {
        if ([[UIScreen mainScreen] bounds].size.height==568)
        {
            [deleteButton setFrame:CGRectMake(530, 10, 30, 30)];   //Frame for  iPhone
            [editButton setFrame:CGRectMake(490, 10, 30, 30)];
        }
        else
        {
            [deleteButton setFrame:CGRectMake(440, 10, 30, 30)];  //Frame for iPhone
            [editButton setFrame:CGRectMake(400, 10, 30, 30)];
        }
    }
 }
 else
 {
    //Portrait mode.
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)    //Frame for iPad
    {
        [deleteButton setFrame:CGRectMake(730, 7, 30, 30)];
        [editButton setFrame:CGRectMake(690, 7, 30, 30)];
    }
    else
    {
        [deleteButton setFrame:CGRectMake(280, 7, 30, 30)];     //Frame for iPhone
        [editButton setFrame:CGRectMake(240, 7, 30, 30)];
    }
 }

 [cell.contentView addSubview:editButton];      //Added button subview to cell.
 [cell.contentView addSubview:deleteButton];

 cell.selectionStyle = UITableViewCellSelectionStyleNone;

 return cell;   //This code is being executed perfectly in iOS 6 also.

I am developing a universal application. But when I launch the application, it works fine in iOS 7, where, as in the case of iOS 6, custom edit and delete buttons appear for the first time when the screen loads. But then when I change the orientation, it disappears from the screen. I overload the table view when changing Orientations, but still it disappears. Can anybody help me. Amazed at the final point of the project.

+4
source share
1 answer

, tableView:cellForRowAtIndexPath:, deleteButton editButton , (, , -reloadData). , , , , , [cell.contentView addSubview:editButton] . , frame, , , .

tableView:cellForRowAtIndexPath: , .

0

Source: https://habr.com/ru/post/1525576/


All Articles