if textField is in your custom cell, you can handle textField ... events in customCell.m too.
if you do, you can call the method simply with [self printStuff]; in
- (BOOL)textFieldShouldReturn:(UITextField *)textField
//CustomCell.h // ... @interface CustomCell : UITableViewCell <UITextFieldDelegate> { //... } -(void)printStuff; @end //CustomCell.m //... -(void)printStuff { //... } -(BOOL)textFieldShouldReturn:(UITextField *)textField { //... [textField resignFirstResponder]; [self printStuff]; return YES; }
or if the printStuff method is in your tableView class, you can declare a protocol
// CustomCell.h @protocol CustomCellProtocol <NSObject> -(void)printStuff:(NSString *)stuff; @end @interface CustomCell UITableViewCell <UITextFieldDelegate> @property (nonatomic, assign)UIViewController<CustomCellProtocol> *parent; // CustomCell.m -(void)printStuff:(NSString *)stuff { [parent printStuff:stuff]; } // TableViewClass.h ... @interface TableViewClass : UITableViewController<CustomCellProtocol> // TableViewClass.m - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { customCell *cell=[tableView dequeueReusableCellWithIdentifier:@"charCell"]; if (cell == nil || (![cell isKindOfClass: customCell.class])) { cell=[[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"charCell"]; cell.parent = self; // or with a custom setter methode } return cell; }
source share