ios - UITextField in TableView Cells -


iam trying add uitextfield dynamically tableview code

(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath  uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath];  uitextfield *textfield = [[uitextfield alloc]initwithframe:cgrectmake(110, 10, 185, 30)]; textfield.tag=temp+indexpath.row+1;  [cell.contentview addsubview:textfield]; 

the problem each time display cell creates newtextfield in same position overlap , cant edit in other textfield , have same tag.. want creat textfield 1 time each cell if displayed again

you need create custom uitableviewcell class

tableviewcellwithtextfield.h

#import <uikit/uikit.h>  @interface tableviewcellwithtextfield : uitableviewcell @property(nonatomic,strong) uitextfield *textfield; @end 

tableviewcellwithtextfield.m

@implementation tableviewcellwithtextfield  - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier {     self = [super initwithstyle:style reuseidentifier:reuseidentifier];     if (self) {         _textfield = [[uitextfield alloc]initwithframe:cgrectmake(110, 10, 185, 30)];         [self addsubview:_textfield];         // initialization code     }     return self; } @end 

and can use textfield this:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     nsstring * cellidentifier= @"cell"     tableviewcellwithtextfield *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath];     if(!cell)     {         cell = [[tableviewcellwithtextfield alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }     cell.textfield.tag = temp + indexpath.row + 1; } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -