我有一个UiViewController,可以导入一个带有一些自定义属性和方法的子类UIView。目前,我可以导入和绘制自定义UIView,同时向我在UIViewController中定义的方法中定义的方法发送消息。
我遇到的问题是,在我的UIViewController中的某些方法中,自定义UIView对象为null,而在其他方法中,它不为null,我可以毫无问题地向它发送消息。
以下是UIViewController的.h文件的样子:
#import "SequencerFrontView.h"
@interface MainViewController : UIViewController
{
SequencerFrontView *sequencerViewFront_01;
}
@property (nonatomic, strong) SequencerFrontView *sequencerViewFront_01;
- (void)createSequencerViewFront_01WithNumberOfSteps:(UInt8)steps;
- (void)recievePulse;
- (void)resetSequencer01;
这是.m文件
#import "SequencerFrontView.h"
@synthesize sequencerViewFront_01;
- (void)createSequencerViewFront_01WithNumberOfSteps:(UInt8)steps
{
SequencerFrontView *sequencerView01 = [[SequencerFrontView alloc]initWithFrame:CGRectMake(500, 100, 225, 225)];
sequencerView01.sequencerSteps = steps;
//make sure view is transparent...this is a custom helper method..works fine
sequencerView01.backgroundColor = RGBCOLOR(0, 0, 0, 0);
//assign newly created view to instance variable
sequencerViewFront_01 = sequencerView01;
[self.view addSubview:sequencerViewFront_01];
}
- (void)recievePulse
{
//call to method works
[sequencerViewFront_01 clockLoop:1];
//NSLog returns object value
NSLog(@"sequencer object is: %@", sequencerViewFront_01);
}
- (void)resetSequencer01
{
//call to method doesn't work and doesn't return an error
[sequencerViewFront_01 resetSequencerStepAtStep:0];
//NSLog returns null for the object value
NSLog(@"sequencer object is: %@", sequencerViewFront_01);
}
正如您所看到的方法非常相似。但是,由于某种原因,resetSequencer01方法不起作用,因为sequencerViewFront_01对象为null。该对象显然已被分配并正在从recivePulse方法接收消息,但我无法弄清楚为什么它在一种方法中为空而在另一种方法中为空。我已经清理了项目,关闭了计算机和ipad,但仍然保持不变。
我已经确认使用NSLog实际上已经达到了这两种方法。
我可以通过recievePulse方法调用它并且它可以正常工作
[sequencerViewFront_01 resetSequencerStepAtStep:0];
但是,在resetSequencer01方法中,它不起作用。我看不出可能有什么不同。也许我错过了一些清除缓存的方法?