开发者

UITextView into UITableViewCell

I'am noob. I need insert UITextView in to UITableViewCell with dynamic resizing and that i would typing right into cell. Pl开发者_如何学编程ease help me resolve this issue.


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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜