我需要一些帮助。
我有一个带有自定义 UITableViewCell 的 UITableView。
在单元格中我有一个 UITextView。
当用户将一些数据输入 UITextView 时,我需要这样做。 UITextView 将根据 UITextView 的内容调整大小。我在 - (void)textViewDidChange:(UITextView *)textView 中实现了它
但现在我还需要调整单元格的大小,如果 UITextView 的内容大小比当前单元格大。
问题是如何通过 UITextView 内容大小调整 UITableView Cell 的大小。
我的代码如下。
@class TableCell;
@interface RootViewController : UITableViewController{
UITableView*tableViewTest;
TableCell *tableCell;
}
@property (nonatomic,retain)IBOutlet TableCell *tableCell;
@property (nonatomic,retain)IBOutlet UITableView*tableViewTest;
@end
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"TableCell" owner:self options:nil];
cell=tableCell;
self.tableCell=nil;
}
[cell setTag:indexPath.row+1];
return cell;
}
- (void)textViewDidChange:(UITextView *)textView
{
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;
NSLog(@"Change=%f",textView.contentSize.height);
}
@interface TableCell : UITableViewCell <UITextViewDelegate>{
UITextView *textViewTest;
}
@property (nonatomic,retain) IBOutlet UITextView *textViewTest;
感谢帮助
不要调用 reloadData,而是使用 [table beginUpdates] 东西
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)