1

these 2 are the files where i m creating a protocol and then declare the delegate in another class

this is my 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

and this is my 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

the error i get is

:- Cannot find protocol declaration for 'FavouritesTableViewControllerDelegate'

I'm declaring these methods and protocols to pass data from FavouriteViewController to ViewController

and this is the protocol method which i call in 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];
}
Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
Shravan
  • 438
  • 3
  • 17

1 Answers1

2

Ths is happening because of recursive import, in FavouritesTableViewController you are importing "ViewController.h" and again ViewController.h you are importing "FavouritesTableViewController.h"

try

@class viewController;
@class FavouritesTableViewController;

in FavouritesTableViewController.h and remove "#import ViewController.h"

Rahul Patel
  • 1,822
  • 12
  • 21
  • if in FavouriteViewController.h i try @class viewController it gives me an error asking for type – Shravan Feb 16 '16 at 12:37
  • the methods in the protocol isnt getting called.. when i go to ViewController – Shravan Feb 16 '16 at 12:45
  • in ViewController.m did you gave `.delegate` = self to FavouriteViewController object? – Rahul Patel Feb 16 '16 at 12:50
  • i have... it seems to be some other problem. i was referring to this article to pass data [link](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) have done exactly the same – Shravan Feb 16 '16 at 13:03
  • 1
    show where you declared .delegate = self in VIewcontroller.m and the method `senDetailsViewController: didFinishEnteringItem` in ViewController.m – Rahul Patel Feb 16 '16 at 13:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103610/discussion-between-shravan-and-rahul-patel). – Shravan Feb 16 '16 at 13:11