2012-01-03 11 views
2

私のアプリでは、MasterViewController、DeviceViewController、およびBRButtonの3つのクラスを使用しています。 BRButtonクラスはすべての実際の作業を行い、ブルートゥース4.0デバイス用のハードウェアデリゲートコールバックを持っています。 BRButtonで何かが起きたとき、他のクラスでメソッドを起動しようとしています。これは、DeviceViewControllerで動作していますが、MasterViewControllerではなく、私はまだかなりの緑色で、何らかのヘルプをプログラムすることで評価されています。ここにいくつかのコードスニペットがあります。
もう1つ言及すべきことは、エラーではないことです。メソッドを呼び出さないだけです。プロトコルを使用したクロスクラス通信

BRButton.h

@protocol RefreshScreen 
-(void) tableTimer:(NSTimer *)timer; 
@end 

@protocol BRButtonDelegate 
@optional 
-(void) bounceBack; 
-(void) tableTimer:(NSTimer *)timer; 
@required 
-(void) buttonReady; 
@end 

@interface BRButton : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate> { 
    NSTimer *myTimer; 
} 

@property (nonatomic,assign) id <BRButtonDelegate> delegate; 
@property (nonatomic,assign) id <RefreshScreen> testCall; 

BRButton.m(ここでは、私は別のクラスで何かを呼び出す2つの異なる場所である。第1は、第二が行う動作しません。)

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { 
    ...does some work then... 
     [[self testCall] tableTimer:nil]; //tableTimer is nil here because no NStimer is used to trigger from this delegate method. 
     printf("New UUID, adding\r\n"); 

    printf("didDiscoverPeripheral\r\n"); 
} 


- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { 
    printf("Disconnecting \r\n"); 
    [[self delegate] bounceBack]; 
} 

MasterViewController .h

@interface MasterViewController : UIViewController < UITableViewDelegate, UITableViewDataSource, RefreshScreen> { 
    BRButton *b; 
} 

MasterViewController.m(これは私のブレークポイントoの後に呼び出すと思いますN didDiscoverPeripheral、それがあることはありません。)

-(void) tableTimer:(NSTimer *)timer { 
    if(b.peripherals.count > 0) 
    { 
     [self.deviceTableView reloadData]; 
    } 
} 

DeviceViewController.h

@interface DeviceViewController : UIViewController <BRButtonDelegate> { 
} 
@property (strong, nonatomic) BRButton *bb; 

DeviceViewController.m

- (void) bounceBack { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

あなたはもう情報が必要な場合は私に知らせてください。 MasterViewController.mで

+1

デリゲートと "testCall"の設定場所を表示できますか?ブレークポイントを使用し、tableTimerを呼び出すときにブレークポイントがゼロでないことを確認してください。 –

+0

それはそれでした。デリゲートは必要なときに設定しますが、testCallを設定しないでください。単純なb.testCall = selfを入力します。今はすべての作業。どうもありがとうございます。 – Merlin910

+1

回答が却下されますので、ご希望の場合は受け入れることができます:P –

答えて

1

tableTimerを呼び出すときにブレークポイントを使用し、 "testCall"プロパティがnilでないことを確認してください。

また、これらのオブジェクトがdeallocされた場合には、testCallを作成し、代わりにweakを委任する必要があります。

0

あなたはBRButtonInstanceは、クラスのインスタンスである

BRButtonInstance.testCall = self; 

を設定する必要があります。あなたはどこかでこれをやっていると確信していますか?

関連する問題