I have create a static UITableView using the storyboard. Each row in the table view contains a textfield and I have given each row an identifier . One of the textfields is used to input a date. I would like show the UIDatePicker when this textfield is selected. I am trying to set the text field’s inputview to a UIDatePicker to accomplish this. I am struggling getting ahold of the UITextField on this particular UITableViewCell. So here is the direction I am going:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
const NSString *birthDateCellIdentifier = @"BirthDateCell";
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString * cellIdentifier = [cell reuseIdentifier];
if(cellIdentifier isEqualToString:birthDateCellIdentifier){
/*this is the cell we're after so get pointer to cell's textfield*/
//set textfield's inputview to UIDatePicker
}
}
Is this the right approach? If so how do I find the textfield on this cell?
Thanks!
No, it isn’t. If you use a different reuse identfier for each cell, the table wiev won’t be able to requeue the cells, so you’ll waste memory. Use the
tagproperty instead.If you have found the cell, you have to add the text field as a property to it, that’s the cleanest way to access it.