You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Objective-C修改通话记录Cell高度遇问题:需统一默认高度

通话记录Cell高度调整失效的解决方法

我刚开始学Objective-C,想调整通话记录列表的Cell高度,让所有Cell保持统一的默认高度,但写了代码后不管试多少数值都不生效,效果显示部分Cell高度明显不一致,有的过高有的过低。

代码如下:

#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

解决步骤

  • 同时设置tableView的rowHeight和estimatedRowHeight属性,避免系统自动估算高度的逻辑干扰。在hook的viewDidLoad方法里添加设置:
%hook MPRecentsTableViewController
- (void)viewDidLoad {
    %orig; // 保留原控制器的初始化逻辑
    self.tableView.rowHeight = 60.5;
    self.tableView.estimatedRowHeight = 60.5;
}

-(NSInteger)tableView:(UITableView *)arg1 numberOfRowsInSection:(NSInteger)arg2 {
    return 200;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60.5;
}
%end
  • 确认MPRecentsTableViewController是通话记录列表的正确控制器类,避免因类名错误导致hook未生效。
  • 检查Cell内部是否存在强制高度的自动布局约束,如果有,需要同步调整约束以匹配设置的Cell高度。

内容的提问来源于stack exchange,提问作者M.abdelwanis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 13:55:55