iphone - How do you use custom UITableViewCell's effectively? -
i making custom uitableview cell shown below. custom uitableviewcell in own nib file calling viewcontroller. (like so)
// registrationviewcontroller.m
//sets number of sections in table - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { return 2; } // sets number of rows in each section. - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return 1; } //loads both custom cells each section - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { //registration cell static nsstring *cellidentifier = @"customregcell"; static nsstring *cellnib = @"logincustomcell"; uitableviewcell *cell = (uitableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:cellnib owner:self options:nil]; cell = (uitableviewcell *)[nib objectatindex:0]; } //registration button static nsstring *cellbuttonidentifier = @"customsubmitcell"; static nsstring *cellbuttonnib = @"loginsubmitbutton"; uitableviewcell *cellbutton = (uitableviewcell *)[tableview dequeuereusablecellwithidentifier:cellbuttonidentifier]; if (cellbutton == nil) { nsarray *nibbutton = [[nsbundle mainbundle] loadnibnamed:cellbuttonnib owner:self options:nil]; cellbutton = (uitableviewcell *)[nibbutton objectatindex:0]; } if (indexpath.section == 0) { cell.selectionstyle = uitableviewcellselectionstylenone; //stops uitableviewcell being selectable [self registrationcontroll]; //todo: call method controls cell return cell; } if (indexpath.section == 1) { cellbutton.selectionstyle = uitableviewcellselectionstylenone; //stops uitableviewcell being selectable return cellbutton; } return nil; }
it has 4 text fields wanting limit size of string can entered five. (i'm trying first text field far not entering textfield:shouldchangecharactersinrange:replacementstring: delegate method (found out while debugging app) here code part trying restrict amount of characters can entered.
// registrationviewcontroller.m
//textfield:shouldchangecharactersinrange:replacementstring: - (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { int length = [regfieldone.text length] ; if (length >= maxlength && ![string isequaltostring:@""]) { regfieldone.text = [regfieldone.text substringtoindex:maxlength]; return no; } return yes; }
i think have limited error 1 of 2 things. maybe haven't set in interface builder correctly.
or has delegation... have general understanding of , why think issue might here, such complex file structure i'm not sure how or if right.
any help, explanations, suggestions etc appreciated.
at point, need set delegate textfield
since put delegate method in registrationviewcontroller.m, can set delegate right after adding cell in - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
.
as long returning subclass of uitableviewcell logincustomcell.xib, can use this:
logincustomcell *cell = (logincustomcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:cellnib owner:self options:nil]; cell = (logincustomcell *)[nib objectatindex:0]; } cell.textfield1.delegate = self; cell.textfield2.delegate = self; cell.textfield3.delegate = self; cell.textfield4.delegate = self; ... return cell;
Comments
Post a Comment