我试图在 aTableViewController
和 a之间设置一个非常基本的委托DetailViewController
,但从未调用过这些方法。这是我的代码:
DetailViewController.h
@protocol DetailViewControllerDelegate
- (void) detailViewControllerDidLike;
- (void) detailViewControllerDidUnlike;
- (void) detailViewControllerDidDislike;
@end
细节视图控制器.m
- (IBAction) changeLikedSwitch: (id) sender
{
UISwitch *likedSwitch = (UISwitch *) sender;
if ([likedSwitch isOn]) {
[_selectedQuote setIsLiked: [NSNumber numberWithBool: YES]];
[self.delegate detailViewControllerDidLike];
} else {
[_selectedQuote setIsLiked: [NSNumber numberWithBool: NO]];
[self.delegate detailViewControllerDidUnlike];
}
NSError *error;
if (![[[CDManager sharedManager] managedObjectContext] save:&error]) NSLog(@"Saving changes failed: %@, %@", error, [error userInfo]);
}
- (IBAction) changeDislikedSwitch: (id) sender
{
UISwitch *dislikedSwitch = (UISwitch *) sender;
if ([dislikedSwitch isOn]) {
[_selectedQuote setIsDisliked: [NSNumber numberWithBool: YES]];
[self.delegate detailViewControllerDidDislike];
[self dismissViewControllerAnimated: YES completion: nil];
} else {
[_selectedQuote setIsDisliked: [NSNumber numberWithBool: NO]];
}
NSError *error;
if (![[[CDManager sharedManager] managedObjectContext] save:&error]) NSLog(@"Saving changes failed: %@, %@", error, [error userInfo]);
}
TableViewController.h 接口行:
@interface TableViewController : UITableViewController <NSFetchedResultsControllerDelegate, DetailViewControllerDelegate>
表视图控制器.m
- (void) detailViewControllerDidLike
{
NSLog(@"detailViewControllerDidLike!");
[self.tableView reloadData];
}
- (void) detailViewControllerDidUnlike
{
NSLog(@"detailViewControllerDidUnlike!");
[self.tableView reloadData];
}
- (void) detailViewControllerDidDislike
{
NSLog(@"detailViewControllerDidDislike!");
[self.tableView reloadData];
}
这些方法都没有被调用。我正在尝试确定是否是因为我没有设置委托,但我不明白我该怎么做。DetailViewController
my中没有 my 的实例TableViewController
,那么我应该如何设置它的属性之一呢?拥有一个我不需要在类之间创建具体链接的委托不是重点吗?这里非常非常困惑。