找不到委托的协议声明

时间:2016-02-16 12:25:44

标签: ios objective-c

这两个是我创建协议然后在另一个类

中声明委托的文件

这是我的favouriteViewController.h

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "ViewController.h"

@class FavouritesTableViewController;

@protocol FavouritesTableViewControllerDelegate<NSObject>

- (void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item;

@end

@interface FavouritesTableViewController : UITableViewController <UISearchControllerDelegate,UISearchBarDelegate>
@property (strong, nonatomic) IBOutlet UISearchController *search;
@property (strong, nonatomic) IBOutlet UITableView *table;
@property (nonatomic, weak) id < FavouritesTableViewControllerDelegate > delegate;
@end

,这是我的viewController.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "FavouritesTableViewController.h"

@interface ViewController : UIViewController <CLLocationManagerDelegate,FavouritesTableViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *weatherIcon;
@property (weak, nonatomic) IBOutlet UILabel *Place;
@property (weak, nonatomic) IBOutlet UILabel *Temperature;
@property (weak, nonatomic) IBOutlet UILabel *unit;
@property (weak, nonatomic) IBOutlet UILabel *weatherText;
@property (weak, nonatomic) IBOutlet UITextView *Info;
@property (weak, nonatomic) IBOutlet UILabel *summary;

@property (strong,nonatomic) NSString *longitude;
@property (strong,nonatomic) NSString *latitude;
@property (strong,nonatomic) NSString *locationName;
@property BOOL setLocation;

@property (weak, nonatomic) IBOutlet UIScrollView *scroll;

- (IBAction)forecast:(UIButton *)sender;
- (IBAction)Share:(UIButton *)sender;
- (IBAction)history:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activIndicator;

- (IBAction)favbutton:(id)sender;

@end

我得到的错误是

  

: - 找不到协议声明   'FavouritesTableViewControllerDelegate'

我宣布这些方法和协议将数据从FavouriteViewController传递到ViewController

这是我在ViewController.m

中调用的协议方法
-(void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item
{
    controller.delegate = self;
    self.latitude = [item[0] valueForKey:@"lat"];
    self.longitude = [item[0] valueForKey:@"long"];
    self.locationName = [item[0] valueForKey:@"name"];
    self.setLocation = YES;
    [self viewDidLoad];
}

1 个答案:

答案 0 :(得分:2)

正在发生这种情况是因为递归导入,在FavouritesTableViewController导入"ViewController.h"并再次ViewController.h导入“FavouritesTableViewController.h

尝试

@class viewController;
@class FavouritesTableViewController;
<{1>}中的

并删除FavouritesTableViewController.h