I am new to iOS world and have run into an issue while trying to pass a value from a TableView back to the home controller.
The scenario that I am working on is
- Home Controller has a button
- Click of button opens a list of items in the second UIViewController
- User selects an item from list
- Selected item is added to another list on Home Controller
Really appreciate any pointers for this issue:
This is how I am preparing for Segue on Home
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destination = segue.destinationViewController;
if ([destination respondsToSelector:@selector(setDelegate:)]) {
[destination setValue:self forKey:@"delegate"];
}
}
SecondController has a delegate id, so I am assuming that delegate is set as "respondsToSelector
" returns true for "setDelegate"
Now, in SecondController when user selects an item I call didSelectRowAtIndexPath
& viewWillDisappear
methods to set the item and make the view disappear:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
POSAllItemsCell *cell = (POSAllItemsCell *) [tableView cellForRowAtIndexPath:indexPath];
item = [NSDictionary dictionaryWithObjectsAndKeys:cell.name, @"Name", cell.price, @"Price", cell.code, @"Code", nil];
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([delegate respondsToSelector:@selector(setSelection:)]) {
[delegate setValue:item forKey:@"selection"];
}
}
Now the problem here is that respondsToSelector
for setSelection
returns false even though I do have setSelection method in my HomeController:
- (void) setSelection:(NSDictionary *)dict {
if (![dict isEqual:selection]) {
......
}
}
Apologies in advance if my question in not clear or is not well formatted. BTW this is for iOS 5 with Xcode 4.2