糨糊Jack

自定义tableviewcell不用nib

customcell.h

@interface Customcell : UITableViewCell<UITextViewDelegate>

{

    UITextField *_textField;

 }

@property (nonatomic,retain) IBOutletUITextField   *_textField;

@end


customcell.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

         //文本

        _textField = [[UITextField alloc] initWithFrame:CGRectMake(180, self.frame.origin.y-20, 120, 20)];

        _textField.textAlignment=UITextAlignmentRight;

        [_textField setBackgroundColor:[UIColorgrayColor]];

        [_textField setEnabled:NO];

        [self addSubview:_textField]; 

         }

    return  self;

}



//调用
// tableview.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Customcell";

    Customcell  *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell = [[[Customcellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];

    //文本

    //cell._textField.frame=CGRectMake(0,0,0,0);

    cell._textField.text =....;

    return newcell;
}

posted on 2012-02-11 11:40  _case  阅读(810)  评论(1)    收藏  举报

导航