自动调整单元格高度

问题描述 投票:0回答:1

你好,我开始学习 obj-c,并希望在编写此代码后增加调用日志单元格,我对单元格高度有很多问题 我希望所有单元格具有相同的默认单元格高度

#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

结果:- enter image description here

多种尺寸没人用

ios objective-c jailbreak
1个回答
0
投票

要在 Swift 中使用自动布局约束启用动态单元格高度,您需要使用根据内容定义其大小的约束来设置单元格。以下是如何实现此目标的示例:

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

或快速

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
© www.soinside.com 2019 - 2024. All rights reserved.