2016-12-19 5 views
0

別のクラスを呼び出すときに「AppDelegate」の目に見える@interface:私は基本的に午前私はこのようなカスタムクラスの実装持っ

... 

@implementation AppDelegate 
... 
-(void)createLabel{ 
    MyNotificationView *view = [[MyNotificationView alloc] initWithFrame:CGRectMake(0,0,100,100)]; 
    view.theid = notification_id; 
} 
-(void)markAsRead:(int)index{ 
    NSMutableArray *arrayofdics = [[[NSUserDefaults standardUserDefaults] objectForKey:@"arrayofdics"] mutableCopy]; 
    NSMutableDictionary *dic = [[arrayofdics objectAtIndex:index] mutableCopy]; 
    [dic setObject:[NSNumber numberWithBool:1] forKey:@"read"]; 
    [arrayofdics replaceObjectAtIndex:index withObject:dic]; 
    [[NSUserDefaults standardUserDefaults] setObject:arrayofdics forKey:@"arrayofdics"]; 
    [self createBodyWindow]; 
    unreadNotifications--; 
    [self setNotificationMenuBar]; 
} 
... 

:その後、

@interface MyNotificationView: NSView 
@property (nonatomic) int theid; 
@end 

@implementation MyNotificationView 
- (void) rightMouseDown:(NSEvent *)event { 
    [self markread]; 
} 
- (void)markread { 
    //call markAsRead in AppDelegate with _theid as param 
} 
@end 

そして、私は私AppDelegateを持っていませんNSViewに右クリックの機能を追加しようとすると、右クリックするとAppDelegateクラス内のメソッドが実行されますが、機能していません。


私が追加しようとしている:

@property (nonatomic) AppDelegate* thisapp; 

@interfaceMyNotificationViewに。そして、追加AppDelegatecreateLabel方法で:何かやっMyNotificationViewmarkAsRead方法で

view.thisapp = self; 

、その後:

を[markAsRead _thisapp:_theid];

が、これはエラーをスローします:

No visible @interface for 'AppDelegate' declares the selector 'markAsRead:' 

どのように私はこれを適切に実装する必要があります。

答えて

1

あなたのメソッドを宣言する必要があります。AppDelegate.hファイル[[UIApplication sharedApplication] delegate];をmarkreadメソッドに使用して、markAdReadメソッドの呼び出しに使用できるインスタンスをアプリケーションデリゲートに取得できます。

関連する問題