Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用协议的跨类通信_Iphone_Objective C - Fatal编程技术网

Iphone 使用协议的跨类通信

Iphone 使用协议的跨类通信,iphone,objective-c,Iphone,Objective C,在我的应用程序中,我使用3个类MasterViewController、DeviceViewController和BRButton。BRButton类完成所有实际工作,并在其中包含bluetooth 4.0设备的硬件委托回调。当BRButton中发生某些事情时,我试图让其他类中的方法触发。这是在DeviceViewController中工作的,但不是在MasterViewController中,我仍然对IOS编程非常熟悉。非常感谢您的帮助。以下是一些代码片段。 我还要提到的一点是,它没有错误,只

在我的应用程序中,我使用3个类MasterViewController、DeviceViewController和BRButton。BRButton类完成所有实际工作,并在其中包含bluetooth 4.0设备的硬件委托回调。当BRButton中发生某些事情时,我试图让其他类中的方法触发。这是在DeviceViewController中工作的,但不是在MasterViewController中,我仍然对IOS编程非常熟悉。非常感谢您的帮助。以下是一些代码片段。
我还要提到的一点是,它没有错误,只是没有调用方法

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;
MasterViewController.h

@interface MasterViewController : UIViewController < UITableViewDelegate, UITableViewDataSource, RefreshScreen> {
    BRButton *b; 
}
@interface DeviceViewController : UIViewController <BRButtonDelegate> {
}
@property (strong, nonatomic) BRButton *bb;
DeviceViewController.h

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

如果你需要更多信息,请告诉我

在MasterViewController.m中,您应该设置

BRButtonInstance.testCall = self;

其中BRButtonInstance是类的实例。您确定在某处执行此操作吗?

在调用tableTimer时,请使用断点并确保“testCall”属性不是nil


此外,您应该使testCall和delegate弱,而不是assign,以防这些对象被解除锁定。

您可以显示您在哪里设置委托和“testCall”吗?使用断点并确保在调用tableTimer时它不是nil。就是这样。我在需要时设置委托,但从未设置testCall。输入一个简单的b.testCall=self;现在一切都好了。非常感谢。我会把答案贴出来,这样你可以接受,如果你愿意的话:P
BRButtonInstance.testCall = self;