2016-12-19 4 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에. 다음 AppDelegate들에있어서 추가 createLabel : 다음

view.thisapp = self; 

와 같은 MyNotificationView S markAsRead 방법 일 무언가 :

[markAsRead _thisapp : _theid]; 내가 제대로이를 구현하는 방법을

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

:

하지만이 오류가 발생합니다.

답변

1

당신은 당신의 방법 나는에게 AppDelegate.h 파일을 선언해야하고 당신은 당신이 당신의 markAdRead 메소드를 호출하는 데 사용할 수있는 앱 위임에 인스턴스를 얻을 수 있도록 markread 방법에 [[UIApplication sharedApplication] delegate];를 사용할 수 있습니다.

관련 문제