ios - How can I edit text in a UITextField when its inside a UITableViewCell? -



ios - How can I edit text in a UITextField when its inside a UITableViewCell? -

i trying create form tableview, have seen one thousand times in other apps, figured simple.

my effort below. added uitextfield content view of uitableviewcell. have tried implementing uitextfielddelegate methods , setting selection style none.

can see doing wrong?

i using canned uitableviewcontroller separate nsobject handle delegate , datasource methods, , custom uitableviewcell subclass.

right when tap cells, not becomefirstresponder, nil happens @ all. tried setting breakpoints in setselected, not appear triggered.

my tableviewcell code

@implementation hstableviewcell - (void)willmovetosuperview:(uiview *)newsuperview { [self.contentview addsubview:self.textfield]; nsdictionary *elements = nsdictionaryofvariablebindings(_textfield); nsarray *verticalconstraints = [nslayoutconstraint constraintswithvisualformat:@"v:|[_textfield]|" options:nslayoutformatdirectionlefttoright metrics:nil views:elements]; nsarray *horizontalconstraints = [nslayoutconstraint constraintswithvisualformat:@"h:|-[_textfield]-|" options:nslayoutformatdirectionlefttoright metrics:nil views:elements]; [self.contentview addconstraints:verticalconstraints]; [self.contentview addconstraints:horizontalconstraints]; } - (void)prepareforreuse { [self.textfield removefromsuperview]; [self.contentview removeconstraints:self.contentview.constraints]; self.textfield = nil; } - (uitextfield *)textfield { if (!_textfield) { _textfield = [uitextfield new]; [_textfield settranslatesautoresizingmaskintoconstraints:no]; [_textfield setplaceholder:@"test"]; } homecoming _textfield; } @end

uitableviewcontroller init

- (uitableviewcontroller *)tableviewcontroller { if (!_tableviewcontroller) { _tableviewcontroller = [[uitableviewcontroller alloc] initwithstyle:uitableviewstyleplain]; [_tableviewcontroller.tableview setdatasource:self.tableviewdatamanager]; [_tableviewcontroller.tableview setdelegate:self.tableviewdatamanager]; [_tableviewcontroller.tableview registerclass:[hstableviewcell class] forcellreuseidentifier:identifer]; } homecoming _tableviewcontroller; }

and uitableviewdelegate/datasource

@implementation hstableviewdatamanger - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming 5; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:identifer forindexpath:indexpath]; homecoming cell; } @end

if interested, test project below

this barebones, trying isolate need accomplish desired behavior.

https://dl.dropboxusercontent.com/u/2396540/textfieldincelltest.zip

i'm not sure why adding text views in willmovetosuperview doesn't work, that's unusual place that. should set code have there initwithstyle:reuseidentifier:, , should delete prepareforreuse method (the text fields added 1 time in init method, there's no need delete them). should give text fields editable.

ios objective-c cocoa-touch uitableview

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -