的Gif
![](https://i.stack.imgur.com/Ubrfv.gif)
細胞自動版式
我添加一個高度約束具有> = 50
![](https://i.stack.imgur.com/tRbQw.png)
代碼
@interface SelfSizingCell()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
@property (weak, nonatomic) IBOutlet UITextView *textview;
@end
@implementation SelfSizingCell
- (void)awakeFromNib {
// Initialization code
self.textview.delegate = self;
self.textview.scrollEnabled = false;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)textViewDidChange:(UITextView *)textView{
CGSize size = [textView sizeThatFits:CGSizeMake(CGRectGetWidth(self.frame), CGFLOAT_MAX)];
CGFloat height = size.height;
if (height < 50) {
self.heightConstraint.constant = 50;
}else{
self.heightConstraint.constant = height;
}
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
@end
.H
@interface SelfSizingCell : UITableViewCell
@property (weak,nonatomic)UITableView * tableView;
@end
而且tableviewController
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"SelfSizingCell" bundle:nil] forCellReuseIdentifier:@"cell"];
self.tableView.estimatedRowHeight = 50;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SelfSizingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.tableView = self.tableView;
return cell;
}
來源
2015-11-19 07:45:02
Leo
爲什麼ü添加TextView的最後一排的UITabeView?我建議將它設置爲TableViewFooter –
@HossamGhareeb:你如何建議更新TableViewFooter的高度? – Nitish
如何嘗試將頁腳框更新爲textView的同一幀?我不確定這會起作用,但給它一個 –