Reputation: 1
I'am noob. I need insert UITextView in to UITableViewCell with dynamic resizing and that i would typing right into cell. Please help me resolve this issue.
Upvotes: 0
Views: 1072
Reputation: 18670
You need to subclass UITableViewCell with a UITextField in it:
@interface CustomCell : UITableViewCell {
UILabel *cellLabel;
UITextField *cellTextField;
}
@property (nonatomic, retain) UILabel *cellLabel;
@property (nonatomic, retain) UITextField *cellTextField;
@end
And then implement:
@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;
}
And finally use your custom cells on:
- (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;
}
Upvotes: 7
Reputation: 54445
This isn't how the standard UITableView is designed to work. There's a defined way of adding/editing/removing items if that's what you're trying to achieve.
I'd recommend having a good read of the Table View Programming Guide for iOS (specifically the "Inserting and Deleting Rows and Sections" section) as this will put you on the right track.
You could of course create a custom view, etc. if you really want to allow users to type into a cell, but as a self-confessed "noob" I wouldn't recommend attempting this until you're more confident with the above approach, etc.
Upvotes: 0