Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField Delegate in UITableView

G'day guys, I'm building an application that allows users to rapidly input numbers into a UITableView.

I've currently built the framework, but I'm having a bit of a hitch hooking up the view to have the keyboard load and make the text in the cell editable from a user action.

I remember there being an iOS example in the dev code somewhere, (like a year ago so it wouldn't be under NDA) where you added items in and edited them within the context of the UITableView without going to a detailed subview.

Just need a hint on how to hook up the delegates, or how to structure the code.

like image 774
Schroedinger Avatar asked Dec 12 '22 19:12

Schroedinger


1 Answers

I have code where I create custom cells for a UITableView which have UITextField and UITextView controls on them. In the UITableViewController code I do this:

Interface

@interface MyTableViewController: 
    UITableViewController <UITextFieldDelegate, UITextViewDelegate> {
....
}

Implementation

-(UITableViewCell *) tableView:(UItableView *) tableView 
    cellForRowAtIndexPath: (NSIndexPath *) indexPath {

    ....

    UITableViewCell * cell = ....
    cell.myTextField.delegate = self;
    cell.myTextField.tag = 1; //This should be unique.
    return cell;
}

-(void) textFieldDidEndEditing: (UITextField * ) textField {
    // Decide which text field based on it's tag and save data to the model.
}

-(void) textViewDidEndEditing: (UITextView * ) textView {
    // Decide which text view based on it's tag and save data to the model.
}
like image 148
drekka Avatar answered Jan 02 '23 04:01

drekka