0

Below is the code I had tried but it's not helpful please check.

static CGFloat cellDefaultHeight = 180;
CGFloat screenDefaultHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat factor = cellDefaultHeight/screenDefaultHeight;
return factor * [UIScreen mainScreen].bounds.size.height;
Iraniya Naynesh
  • 1,125
  • 3
  • 14
  • 26

3 Answers3

1

In Swift

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
    let screenHeight = UIScreen.main.bounds.height  
    return (cellDefaultHeight/screenDefaultHeight) * screenHeight
}

In Objective C

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
       CGFloat screenDefaultHeight = [UIScreen mainScreen].bounds.size.height;
        CGFloat factor = cellDefaultHeight/screenDefaultHeight;
        return factor * [UIScreen mainScreen].bounds.size.height;
    }
Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
0

You should use heightForRowAtIndexPath delegate method of UITableView.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [UIScreen mainScreen].bounds.size.width;
}
Community
  • 1
  • 1
Let's_Create
  • 2,963
  • 3
  • 14
  • 33
0

its a logical error Try this.

static CGFloat cellDefaultHeight = 180; //lets suppose its a defualt height for iphone6
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat factor = cellDefaultHeight * (screenHeight / 667) //667 is height of iphone 6
return factor * cellDefaultHeight;
Taimoor Suleman
  • 1,588
  • 14
  • 29