【发布时间】:2012-06-30 04:42:15
【问题描述】:
我想做的是:
首先,TopPlacesViewController 与 SinglePlacePhotosViewController 类(TableView 控制器)有一个转义。
我在TopPlacesViewController类中创建了一个delegate,然后使用prepareforSegue方法将SinglePlacePhotosViewController设置为delegate并实现protocol方法。
然后当我点击TopPlacesViewController(TableView 控制器)中的一张照片时,它会调用TopPlacesViewController 方法,该方法应该会显示该位置的一些照片。
但我一直收到此错误:
[SinglePlacePhotosViewController setDelegate:]:无法识别的选择器发送到实例 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。
-
其实我只是查了一下。
-
这很奇怪。
SinglePlacePhotosViewController定义了吗? -
是的,您能显示更多
SinglePlacePhotosViewController的@interface 代码吗?看起来您的委托缺少 @property。 -
我已经为代理设置了@property
标签: objective-c delegates cs193p