我想要做的事情是:委托错误
首先,TopPlacesViewController
有SEGUE到类SinglePlacePhotosViewController
(一TableView
控制器)。
我在TopPlacesViewController
类中创建一个委托,然后使用prepareforSegue
方法将SinglePlacePhotosViewController
设置为委托并实现协议方法。
然后,当我点击TopPlacesViewController
(TableView控制器)中的一张照片时,它会调用方法TopPlacesViewController
,该方法应显示来自该位置的一些照片。
但我一直收到此错误:
[SinglePlacePhotosViewController setDelegate:]: unrecognized selector sent to instance 0xc94cc20
我TopPlacesViewController.h
文件:
@class TopPlacesViewController;
@protocol TopPlacesViewControllerDelegate
- (void)topPlacesViewControllerDelegate:(TopPlacesViewController *)sender
showPhotos:(NSArray *)photo;
@end
@interface TopPlacesViewController : UITableViewController
@property (nonatomic,weak) id <TopPlacesViewControllerDelegate> delegate;
@end
TopPlacesViewController.m
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *place = [self.places objectAtIndex:indexPath.row];
self.singlePlacePhotos = [FlickrFetcher photosInPlace:place maxResults:50];
[self.delegate topPlacesViewControllerDelegate:self showPhotos:self.singlePlacePhotos];
[self performSegueWithIdentifier:@"Flickr Photos" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"Flickr Photos"]) {
[segue.destinationViewController setDelegate:self];
}
}
在这个
然后,我实现委托:
@interface SinglePlacePhotosViewController() <"TopPlacesViewControllerDelegate">
- (void)topPlacesViewControllerDelegate:(TopPlacesViewController *)sender showPhoto:(NSArray *)photo
{
self.photos = photo;
}
segue.destinationViewController的定义没有-setDelegate。 – Vervious
实际上,我只是看着它。 – Pan
这很奇怪。 SinglePlacePhotosViewController是否定义了它? – Vervious