auto resize cell heights

56 Views Asked by At

hello i start learning obj-c and want to increase call log cells after write this code i have many issues with cell heights i want to have same default cell heights for all cells

#import <UIKit/UIKit.h>
#import <UIKit/UITableViewController.h>
#import <Foundation/Foundation.h>


@interface MPRecentsTableViewCell
@property (readwrite, strong, nonatomic) UITableView * tableView;
@property (readwrite, assign, nonatomic) long long tableViewDisplayMode;
@property (readwrite, strong, nonatomic) UISegmentedControl * tableViewDisplayModeSegmentedControl;
@property (readwrite, assign, nonatomic) bool tableViewNeedsReload;
@end


%hook MPRecentsTableViewController
//-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

-(NSInteger)tableView:(UITableView *)arg1 numberOfRowsInSection:(NSInteger)arg2 {
    return 200;
  }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60.5;
}

%end

result:- enter image description here

many size no one work

1

There are 1 best solutions below

2
Hiten Pethani On

To enable dynamic cell height with Auto Layout constraints in Swift, you need to set up your cell with constraints that define its size based on the content. Here's an example of how you can achieve this:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

or in swift

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }