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]; } 
3
  • It seems that you declared it in favouriteViewController.h but included another FavouritesTableViewController.h Commented Feb 16, 2016 at 12:28
  • Refer this - Here Seems like a similar problem. Commented Feb 16, 2016 at 12:54
  • @PulkitSharma nope i have seeen that post its not the problem i am facing thanks Commented Feb 16, 2016 at 13:02

1 Answer 1

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"

Sign up to request clarification or add additional context in comments.

6 Comments

if in FavouriteViewController.h i try @class viewController it gives me an error asking for type
the methods in the protocol isnt getting called.. when i go to ViewController
in ViewController.m did you gave .delegate = self to FavouriteViewController object?
i have... it seems to be some other problem. i was referring to this article to pass data link have done exactly the same
show where you declared .delegate = self in VIewcontroller.m and the method senDetailsViewController: didFinishEnteringItem in ViewController.m
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.