In my app I am using 3 classes MasterViewController, DeviceViewController, and BRButton. The BRButton class does all of the real work, and has the hardware delegate callbacks in it for bluetooth 4.0 devices. I am trying to get methods to fire in the other classes when something happens in BRButton. This is working in DeviceViewController, but not in MasterViewController, I’m still pretty green with IOS programing any help is appreciated. Here is some code snippets.
One more thing I should mention is it doesn’t error, it just doesn’t call the method.
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 (here is 2 different places I call something in a different class. First one doesn’t work the second does.)
- (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 (I would expect this to be called after my break point on didDiscoverPeripheral, but it never is.)
-(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];
}
If you need anymore information let me know.
Use a breakpoint and make sure the “testCall” property isn’t nil when you call tableTimer on it.
Also, you should make testCall and delegate weak instead of assign in case those objects get dealloc’d.