0 resize insert objective-c uitableview uitextview
我是菜鸟.我需要将UITextView插入UITableViewCell并进行动态调整大小,并且我会在单元格中输入.请帮我解决这个问题.
您需要使用UITextField为UITableViewCell创建子类:
@interface CustomCell : UITableViewCell {
UILabel *cellLabel;
UITextField *cellTextField;
}
@property (nonatomic, retain) UILabel *cellLabel;
@property (nonatomic, retain) UITextField *cellTextField;
@end
Run Code Online (Sandbox Code Playgroud)
然后执行:
@implementation CustomCell
@synthesize cellLabel, cellTextField;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
cellLabel = [[UILabel alloc] initWithFrame:CGRectZero];
... // configure your label appearance here
cellTextField = [[UITextField alloc] initWithFrame:CGRectZero];
... // configure your textfield appearance here
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
最后使用您的自定义单元格:
- (CustomCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
... // configure your cell data source here
return cell;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1052 次 |
| 最近记录: |