I have a custom cell. In it is a UITextField linked to customCell.m. I\'m trying to pass the text from the textField to mainVC.m
There is a much easier way of doing this.
This is assuming you are doing this all programatically and that you have your custom cell set up correctly with the textField working.
First you need to make your textField accessible from outside the custom cell. You do this in the normal way of putting it in the header file as a property:
customCell.h
@property (weak, nonatomic) IBOutlet UITextField * customTextField;
Make sure you allocate it in the custom cell XIB.
Now we have a pointer to our custom textField when we access the cell in cellForRowAtIndex of your main view controller:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Adding the cell - remember to add the identifier to the xib file
BCustomCell * cell = [tableView dequeueReusableCellWithIdentifier:bCustomCellIdentifier];
// We can now access our cell's textField
cell.textLabel.text = cell.customTextField.text;
return cell;
}
Hopefully this helps you out.