Question

So far, have read a few posts, such as this and this, but they have not really helped with my situation.

I'm creating a dynamic form for iPad using 'plain' style UITableViews. I have multiple different UITableViews on the page, so I defined a separate object to server as my datasource and delegate. I understand how to change the text of each cell using the datasource; however, I have no clue how to link the UITextFields in my prototype cells to an IBAction. I could figure out how to create a single IBAction for all textfields in my table, such that they all update the same data, but I don't know how to have each UITextField have a one-to-one correspondence with my datasource.

Here is my prototype cell:

My prototype cell

and my code thus far:

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myPrototypeCell"];

    UILabel *buildingNumber = (UILabel *)[cell viewWithTag:100];        
    buildingNumber.text = [@"Building " stringByAppendingString:self.dataSource[indexPath.row][@"buildingNumber"]];

    return cell;
}

self.dataSource is an NSMutableArray of NSMutableDictionaries. Any help whatsoever is appreciated.

Was it helpful?

Solution

I initially thought you were referring to IBOutlets so my previous answer is somehow wrong but the inherent idea is still the same.

You cannot have IBActions or IBOutlets from a prototype cell unless the cell is subclassed. You can do so if the cells are static though, not that it can help in your case. Subclassing the UITableViewCell is not too hard or too bad, in fact if in the future you want to speed things up on your TableView, that is one of the many ways to start.

OTHER TIPS

This tutorial provides a few different options for dealing with information inside a table view cell:

http://mobile.tutsplus.com/tutorials/iphone/customizing-uitableview-cell/

I almost always use a UITableViewCell subclass to deal with outlets and actions inside the cell. But this should be a decision you make based on your own architecture.

Hope this helps!

you need single for all your textField.So do the following:

Get the text field as your are getting label

UITextField *yourTextField = (UITextField *)[cell viewWithTag:101]; 
[yourTextField addTarget:self action:@selector(clickTextField:) forControlEvents:UIControlEventEditingChanged];

clickTextField method will get invoke for every Text Field.

Hope this helps.

Edit: Forgot to mention, you can you set delegate of UItextField and get a notification in UITextFieldTextDidChange: delegate method

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top