0

I created master details template project in xcode 4.6 and I added custom cell with 2 textfields. Since I can't create outlets for textField in UITableViewController I had to create new class DataCell which is subclass of UITableViewCell. Now I don't know how to pass data from DataCell to viewController or any other class?

All the protocol and delegate tutorials are focused on viewControllers so I always end with some line like below:

[self presentModalViewController:enterAmountVC animated:YES];

I obviously cannot use this as my class doesn't have any model or push connection. So question is how to transfer data in this case? Make DataCell which is subclass of UITableViewCell a model class?

James Douglas
  • 736
  • 1
  • 11
  • 20

1 Answers1

0

You not need to pass data from DataCell. Cells mostly use for displaying data and not for storing. If you are using UITableView I suppose that you are also using some array as your UITableView's dataSource. So you can get your data from array. If you have cell you can get it's index in your array using

NSIndexPath *indexPath = [tableView indexPathForCell:cell];
if (indexPath)
{
    DataModel *dataModel = [myDataArray objectAtIndex:indexPath.row];
}

Now you can use dataModel to get needed data and pass it to you UIViewController.

If all information stored in your cell's textfields you need to create properties for your textfields in DataCell class and then get information through these properties.

Artem Shmatkov
  • 1,434
  • 5
  • 22
  • 41
  • I have custom cell with textFields so this wouldn't work. – James Douglas Apr 02 '13 at 11:29
  • Of course :) if you will explain clearly why `textFields` existence can affect achieving dataModel I will try to help you. – Artem Shmatkov Apr 02 '13 at 11:31
  • As per specification I need cell with 2 textfields for entering pair numbers. User can add any number of pairs. If I would have only simple cell with title I would be able to get data easy. How would datamodel in your example distinguish between two cells how would I even get that data can show this in code. – James Douglas Apr 02 '13 at 11:38