初心者なので、デリゲートを理解するのが非常に難しいと感じているので、できる限り質問をしようと思います。
Connection.m を Controller.h のデリゲートにしたい。私の Controller.h には
@protocol HeliControllerDelegate <NSObject>
@optional
- (void) measurementUpdated:(NSNumber *) measurement;
- (void) didDiscoverCharacteristic; // neh
@end
@interface HeliController : UIViewController <CBPeripheralDelegate>
@property (nonatomic, assign) id<HeliControllerDelegate> delegate;
@end
Controller.m で合成します。
@synthesize delegate = _delegate;
インターフェイス宣言の前。Controller.m で didDiscoverCharacteristic を呼び出す
- (void) peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
NSLog(@"Did discover characteristic for service %@", [service.peripheral UUID]);
for(CBCharacteristic *c in [service characteristics]){
if([[c UUID] isEqual:HeliController.throttleCharacteristicUUID]){
NSLog(@"Found throttle characteristic");
self.throttleCharacteristic = c;
[self.delegate didDiscoverCharacteristic];
}
}
}
委任ファイル Connection.h で、私は
@interface Connection : UIViewController <CBCentralManagerDelegate, ControllerDelegate> {
}
Controller.h のプロトコルのメソッドを使用できるようにしますが、プログラムが didDiscoverCharacteristic 呼び出しを実行しても、Connection.m のメソッド実装では何も起こりません。
これに関するすべてのヘルプは本当に感謝しています。