I’m having TableView as my MainView and viewcontroller as my Second view. The view controller has 3 textfields..I’m writing protocol so that I can get the values of Textfileds and can add into array of Tableview. The purpose is Whatever I give it in the textfield must get added in to the Table cell.
I’m having secondviewcontroller.h
@property (nonatomic,assign) id<secondviewcontrollerDelegate> delegate;
@protocol secondviewcontrollerDelegate<NSObject>
- (void)additemsintoarray;
@end
secondviewcontroller.m
-(IBAction)ok:(id)sender
{
[self.delegate additemsintoarray];
}
In Tableview.h
@interface RootViewController : UITableViewController<secondviewcontrollerDelegate>
in tableview.m
- (void)additemsintoarray
{
[self.array1 insertObject:scontroller.iditem1.text atIndex:[array1 count]];
[self.array1 insertObject:scontroller.nameitem1.text atIndex:[array1 count]];
[self.array1 insertObject:scontroller.iditem1.text atIndex:[array1 count]];
[[self navigationController]popViewControllerAnimated:YES];
}
Note: the array is declared in Tableview with some values….
I’m getting an Error:
Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[UIView additemsintoarray:]: unrecognized selector sent to instance
Your
RootViewControllershould be the delegate. You have this issue because of an UIView is connected as a delegate of yourSecondViewController.Hope this helps