2017-01-18 6 views
0

クラスメソッドからインスタンスメソッドにアクセスしようとしています。私は、このエラーObjective-cクラスメソッドからメソッドを呼び出す

を取得しています

+ [ActiveVC goToDashBoard]:「+ [ActiveVC goToDashBoard]: 認識されていないセレクタがキャッチされない例外により 'NSInvalidArgumentException'、理由にアプリを終了クラス0x112010

***に送信認識されていないセレクタは、クラス0x112010'

私のコードに送ら

+ (void) removeClosedVisitor:(NSString *) visitorID{ 

    for (NSInteger i = activelist.count - 1; i >= 0 ; i--) { 
     ActiveItemObject *item = [activelist objectAtIndex:i]; 
     if ([visitorID isEqualToString:item.VisitorId]) { 
      NSLog(@"Removing Visitor from Active List -- %@", visitorID); 
      [activelist removeObjectAtIndex:i]; 
      //[self.incommingTable reloadData]; 

//   NSDictionary *activeDictionary = [[NSDictionary alloc] init]; 
//   activeDictionary = [activelist mutableCopy]; 
//    
//   [[NSNotificationCenter defaultCenter] 
//    postNotificationName:@"PassData" 
//    object:nil 
//    userInfo:activeDictionary]; 

      [[self class] goToDashBoard]; 
     } 
    } 
} 



- (void) goToDashBoard{ 
    NSLog(@"Segue to Dashboard"); 
    UITabBarController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"id_tabView"]; 
    [dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; 
    [self presentViewController:dvc animated:YES completion:nil]; 

} 

この問題を解決するお手伝いができます。 tnx。

+1

' - (void)goToDashBoard'はインスタンスメソッドです。インスタンスを持たないAccessibleのクラスメソッドにしたい場合は、署名を '+(void)goToDashBoard'に変更してください – NSNoob

答えて

0

インスタンスメソッドを呼び出す場合は、インスタンス変数が必要になりますので、このクラスのインスタンス変数を作成して呼び出します。

0

実際にどこにでもインスタンスがありますか?そうでない場合は、次のものを作成する必要があります。

[self.sharedInstance goToDashBoard] 

[[self alloc] init] goToDashBoard] 

インスタンスはビューコントローラのように見えるので、私はあなたがインスタンスを持っていると仮定します。この場合、インスタンスを静的メソッドに渡すことをお勧めします。

+ (void) removeClosedVisitor:(NSString *) visitorID viewController: (xxx) viewController { 
3

クラスのインスタンスを作成するか、クラスをシングルトンに変換する必要があります。たとえば:[[ActiveVC sharedInstance] goToDashBoard];

は、ここでは、シングルトンクラスを作成する方法は次のとおりです。

まず、新しいファイルを作成し、NSObjectからそれをサブクラス化。名前を付けて、ここではCommonClassを使用します。 XcodeはCommonClass.hとCommonClass.mファイルを生成します。あなたのCommonClass.mファイルに

#import <Foundation/Foundation.h> 

@interface CommonClass : NSObject { 
} 
+ (CommonClass *)sharedObject; 
@property NSString *commonString; 
@end 

:あなたのCommonClass.hファイルで

#import "CommonClass.h" 

@implementation CommonClass 

+ (CommonClass *)sharedObject { 
    static CommonClass *sharedClass = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     sharedClass = [[self alloc] init]; 
    }); 
    return sharedClass; 
} 

- (id)init { 
    if (self = [super init]) { 
     self.commonString = @"this is string"; 
    } 
    return self; 
} 

@end 
0

goToDashBoardクラスメソッドを作成します。ここにインスタンスを作成していないので、クラスメソッドでなければ実行できません。

+ (void) goToDashBoard 
関連する問題