I am trying to figure out how to take the delegate in LocationViewController and SetScoringTableViewController and implement both of them in GameDetailsTableViewController. LocationViewControllerDelegate was already working, but when I added the new SetScoringTableViewController, the program had an error.
LocationViewController.h
#import "ViewController.h"
#class LocationViewController;
#protocol LocationViewControllerDelegate <NSObject>
- (void)addItemViewController:(LocationViewController *)controller didFinishEnteringItem:(NSString *)name;
#end
#interface LocationViewController : UIViewController
#property (nonatomic, weak) id <LocationViewControllerDelegate> delegate;
#end
SetScoringTableViewController.h
#import <UIKit/UIKit.h>
#import "GameDetailsTableViewController.h"
#import "LocationViewController.h"
#class SetScoringTableViewController;
#protocol SetScoringTableViewControllerDelegate <NSObject>
- (void)addItemViewControllerSS:(SetScoringTableViewController *)SScontroller didFinishEnteringItemSS:(NSString *)SSname;
#end
#interface SetScoringTableViewController : UITableViewController
#property (nonatomic, strong) id <SetScoringTableViewControllerDelegate> SSdelegate;
#end
GameDetailsTableViewController.h
#import <UIKit/UIKit.h>
#import "LocationViewController.h"
#import "SetScoringTableViewController.h"
#interface MainViewController : UITableViewController <LocationViewControllerDelegate, SetScoringTableViewControllerDelegate>
When I run this I get an error: "Cannot find protocol declaration for 'SetScoringTableViewControllerDelegate' even though I have.
The only way I have found to fix this problem is to put the "SetScoringTableViewController delegate in the LocationView Controller, but I know that is not right. Any help would be greatly appreciated.
You have a dependency loop:
SetScoringTableViewController.h
#import "GameDetailsTableViewController.h"
GameDetailsTableViewController.h
#import "SetScoringTableViewController.h"
But it looks like you can remove the #import "GameDetailsTableViewController.h" as there is no mention of it in the header file.
What you're experiencing is an an #import cycle. To break the import loop
remove this import line:
#import "GameDetailsTableViewController.h"
from SetScoringTableViewController.h and put it in a .m file.
Try to separate the delegate on a different .h file.
Related
I have a custom delegate that I have created for a subclass of UITextField. In the delegate class, I've declared an enum like this:
MyCustomDelegate.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "MyCustomTextField.h"
#interface MyCustomDelegate : NSObject <MyDelegate, UITextFieldDelegate>
#property (nonatomic, strong)MyCustomTextField *customTextField;
#end
MyCustomTextField.h:
#import <UIKit/UIKit.h>
typedef enum {
EnumTypeA,
EnumTypeB,
EnumTypeC,
EnumTypeD,
EnumTypeE
} MyEnumType;
#class MyCustomDelegate;
#protocol MyDelegate <NSObject>
#required
- (void)methodA;
- (void)methodB;
#end
#interface MyCustomTextField : UITextField
#property (nonatomic, weak)id <MyDelegate>myDelegate;
#property (nonatomic) MyEnumType enumType;
#end
Now, I am trying to use this enum in conjunction with my custom UITextField elsewhere in my project, like this:
MyViewController.h
#import "MyCustomTextField.h"
#import "MyCustomDelegate.h"
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController
#property (weak, nonatomic) IBOutlet MyCustomTextField *mySampleTextField;
#end
MyViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
[self.mySampleTextField setMyEnumType:EnumTypeA];
}
However, I am getting the error, "No visible #interface for 'MyCustomTextField' declares the selector 'setMyEnumType'".
Can anyone see what it is I'm doing wrong?
Objective-C will automatically generate setter for you based on the name of the property (enumType) instead of the name of type (MyEnumType). So your setters should be the following instead:
[self.mySampleTextField setEnumType:EnumTypeA];
I've declared a protocol named ScrollableTimelineViewProtocol in a file ScrollableTimelineView.h as below :
#import <UIKit/UIKit.h>
#import "AbstractView.h"
#import "RedTimeIndicator.h"
#import "EventsModel.h"
#import "TimeStrands.h"
#define LABEL_TAG_OFFSET -500
#protocol ScrollableTimelineViewProtocol <NSObject>
- (void) showPopup : (NSInteger)tag;
#end
#interface ScrollableTimelineView : UIView<TimeStrandDelegate,UIScrollViewDelegate>
{
}
#property (nonatomic,assign) id<ScrollableTimelineViewProtocol> delegate;
And I'm trying to use it in a view controller :
#import <UIKit/UIKit.h>
#import "AbstractViewController.h"
#import "TimeStrands.h"
#import "ScrollableTimelineView.h"
#protocol TimelineDelegate <NSObject>
- (void) detailedShownDelegate;
- (void) detailedViewHiddenDelegate;
#end
#interface TimelineViewController : UIViewController<ScrollableTimelineViewProtocol>;
But I get an error saying Could not find protocol declartion for ScrollableTimelineViewProtocol. Help.
There should not be semicolon at the end
Import the class where ScrollableTimelineViewProtocol declared.
#protocol scrollableTimelineViewProtocol;
#property (strong, nonatomic) IBOutlet UITableView *tblView;
#property (strong, nonatomic) IBOutlet id<scrollableTimelineViewProtocol> delegate;
#end
#protocol scrollableTimelineViewProtocol <NSObject>
-(void)runFast;
#end
Just simple... Try this...
Remove semocolon from interface..
#interface TimelineViewController : UIViewController<ScrollableTimelineViewProtocol>;
Into
#interface TimelineViewController : UIViewController<ScrollableTimelineViewProtocol>
This code :
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MessageUI/MessageUI.h>
#import "MessageComposerViewController.h"
#import <MessageUI/MFMailComposeViewController.h>
#interface MapViewController : UIViewController <MFMailComposeViewControllerDelegate> // Add the delegate
- (IBAction)showEmail:(id)sender;
{
IBOutlet MKMapView *mapView;
}
#property (nonatomic, retain) MKMapView *mapView;
#end
This problem or error :
Cannot find protocol declaration for 'MFMailComposeViewControllerDelegate'; did you mean 'UIPageViewControllerDelegate'?
for this lign : #import "MessageComposerViewController.h"
Expected identifier or '('
for this lign : #interface MapViewController : UIViewController // Add the delegate
and this lign : {
Thanks for advance. :)
Try This,
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MessageUI/MessageUI.h>
#import "MessageComposerViewController.h"
#import <MessageUI/MFMailComposeViewController.h>
#interface MapViewController : UIViewController <MFMailComposeViewControllerDelegate,UINavigationControllerDelegate> {
IBOutlet MKMapView *mapView;
}
- (IBAction)showEmail:(id)sender;
#property (nonatomic, retain) MKMapView *mapView;
#end
If you do the above and still see the warning in Xcode, try building or building & running your app. Sometimes these warnings linger after you've addressed the problem and are cleared out by a compilation cycle.
I encountered the same problem today coding an app for ios8.
First thing that I did was re-add the framework, but it didn't help. The problem was I ignored libAWDProtobufFacetimeiMessage - a protocol buffer file. I'm no professional to guess why, but when I added both buffer and the framework itself, the error message disappeared. I have posted a screenshot here. Hope my answer helps anyone looking here in the future.
I am running an ARC 'refactor' on an old iOS app.
However, I am getting the following error
Receiver type 'WarningCallback' for instance message is a forward declaration
WarningCallback.h
#class WarningCallback;
#import <UIKit/UIKit.h>
#import "WebViewController.h"
#import "Constants.h"
#protocol WarningCallback
-(void) warningDismissedAndNavigateToCall:(BOOL) navigateToCall;
#end
#interface WarningViewController : WebViewController {
}
#property (nonatomic,retain) WarningCallback* parentVC;
#end
WarningCallback.m
#import "WarningViewController.h"
#implementation WarningViewController
#synthesize parentVC;
...
-(IBAction) done:(id) sender {
[[self parentVC] warningDismissedAndNavigateToCall:NO];
}
#end
The error occurs on the following line of WarningCallback.m
[[self parentVC] warningDismissedAndNavigateToCall:NO];
The error is because of the line #class WarningCallback;. The error message means that the compiler found a forward declaration of WarningCallback, but is not able to find the corresponding implementation. That's because WarningCallback is not a class, but a protocol.
If you want to forward declare a protocol you can do so as follows:
#protocol WarningCallback;
#interface WarningViewController : WebViewController
#property (nonatomic, weak) id<WarningCallback> parentVC;
#end
#protocol WarningCallback
- (void)warningDismissedAndNavigateToCall:(BOOL) navigateToCall;
#end
Note how I've declared parentVC.
Remove the line:
#class WarningCallback;
When declaring a #protocol, it is not necessary to also declare it as a #class unless you have a specific reason to do so. See:
What's with the declare a class and declare a protocol with the same name?
Xcode has showed out of the blue this error: "Unknown type name"
I'll explain:
My StoriesViewController.h:
#import <UIKit/UIKit.h>
#import "Stories.h"
#interface StoriesViewController : UIViewController <UITextViewDelegate>
#property (strong) Stories *story; //Here it goes- "Unknown type name `Stories`"
#property (weak) IBOutlet UITextView *storyView;
#end
In my Stories.h:
#import <UIKit/UIKit.h>
#import "ViewController.h"
#interface Stories : UIDocument
#property (strong) NSString * storyContent;
#end
Again, out of the blue.
Thanks in advance.
EDIT:
In my ViewController.h:
#import <UIKit/UIKit.h>
#import "Stories.h"
#import "StoriesViewController.h"
#import "StoriesPickerViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface ViewController : UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
}
#end
NB #class throws loads of ARC issues.
I have removed useless references to ViewController.h, worked.
SOLVED!
You have a circular reference problem.
What's happening is that when you load your ViewController it goes through it's imports, it loads Stories.h, it goes to load it's imports and it goes back to ViewController.h, so you are stuck in an infinite loop there.
Either remove one of the conflicting imports, or use forward class declaration (that example is for C++, see here for an example with Objective-C)