【发布时间】:2011-07-04 16:03:18
【问题描述】:
我需要一些帮助。 我有一个带有自定义 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;
感谢您的帮助
【问题讨论】:
标签: ios uitableview uitextview