Trong suốt ứng dụng của tôi, tôi nhận được cảnh báo vấn đề ngữ nghĩa khi đặt ViewController.delegate = self
. Tôi đã tìm kiếm và tìm thấy các bài viết tương tự nhưng không ai có thể giải quyết vấn đề của tôi.Chỉ định cho 'id <Delegate>' từ loại không tương thích 'ViewController * const_strong'
ViewController.m:
GameAddViewController *gameAddViewContoller = [[navigationController viewControllers] objectAtIndex:0];
gameAddViewContoller.delegate=self;
Tôi nhận được thông báo lỗi khi thiết .delegate=self
.
GameAddViewController.h:
@protocol GameAddViewControllerDelegate <NSObject>
- (void)gameAddViewControllerDidCancel:(GameAddViewController *)controller;
- (void)gameAddViewController:(GameAddViewController *)controller didAddGame:(Game *) game;
@end
@interface GameAddViewController : UITableViewController <GameAddViewControllerDelegate>
{
sqlite3 *pitchcountDB;
NSString *dbPath;
}
@property (nonatomic, strong) id <GameAddViewControllerDelegate> delegate;
...
@end
ViewController.h:
#import "GameAddViewController.h"
@class ViewController;
@protocol ViewControllerDelegate <NSObject>
- (void)ViewControllerDidCancel:(ViewController *)controller;
@end
@interface ViewController : UIViewController <ViewControllerDelegate>
-(void) checkAndCreateFile;
@end
bất cứ ai có thể chỉ cho tôi đi đúng hướng để giải quyết các thông điệp cảnh báo?
Tôi cần phải làm gì để khắc phục điều này. Có cái gì tôi cần phải thay đổi trong giao thức GameAddViewController? –
Vâng, nó phụ thuộc vào người bạn muốn làm đại biểu của bạn. Ai đang thực hiện giao thức GameAddViewController – giorashc
GameAddViewController là con của ViewController và tôi đang triển khai phương thức gameAddViewControllerDidCancel trong ViewController. Thông báo lỗi là từ phương thức prepareForSegue trong ViewController khi tôi đặt gameAddViewContoller.delegate = self. –