Rotate a custom UITableViewCell

前端 未结 6 621
有刺的猬
有刺的猬 2020-12-29 14:36

I have a custom UITableViewCell which contains several UIButtons. Each button\'s frame position is relative to the cell width. I set autoresizingMask=UIViewAutoresizingFlexi

6条回答
  •  死守一世寂寞
    2020-12-29 15:07

    You'll need to fix your cells frame width (assuming the height is same in portrait and landscape mode) within your cellForRowAtIndexPath method. That is what is working here. I used to create a custom TableViewCell with IB and it is always initialised for portrait 320 px width. With defining the frame it works as expected, even if the cell is "reused" from queue.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     ...
     UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
     if (cell == nil) {
        // create cell here...
     }
    
     // Adjust cell frame width to be equal to tableview frame width
     cell.frame = CGRectMake(0, 0, tableView.frame.size.width, cell.frame.size.height);
     ...
    }
    

提交回复
热议问题