没有可见的@interface声明选择器

时间:2013-12-11 18:50:48

标签: ios objective-c

我有SSLYFoodDetailViewController.h,其内容为

#import <UIKit/UIKit.h>

@interface SSLYFoodDetailViewController : UIViewController

@property(nonatomic, weak) NSString *foodItem;
@property(nonatomic, weak) NSString *restaurantName;

- (void) setFoodItem:(NSString *)foodItem;
- (void) setRestaurantName:(NSString *)restaurantName;

@end

SSLYTableViewController.m方法中的另一个文件prepareForSegue中,我尝试执行以下操作 -

SSLYFoodDetailViewController *sslyFoodDetailViewController = [segue destinationViewController];
[sslyFoodDetailViewController setFoodItem:@"Pasta"];

XCode给出了一个错误,即No visible @interface for 'SSLYFoodDetailViewController' declares the selector 'setFoodItem'

SSLYTableViewController.m的顶部,我有导入声明 -

#import "SSLYFoodDetailViewController.h"

我错过了什么?

1 个答案:

答案 0 :(得分:0)

这没有任何意义,只是foodItem setFoodItem:声明隐含@property

尝试删除标题中setFoodItem:setRestaurantName:的声明 - 这绝对不会对任何内容产生任何影响,因为它们是多余的。

如果这不起作用,请尝试使用属性访问符号:

sslyFoodDetailViewController.foodItem = @"Pasta";

另外值得注意的是,你可能会收到警告:

SSLYFoodDetailViewController *sslyFoodDetailViewController = [segue destinationViewController];

您应该在该行中添加显式强制转换,如下所示:

SSLYFoodDetailViewController *sslyFoodDetailViewController = (SSLYFoodDetailViewController *) [segue destinationViewController];