我正在为 iOS 7 开发,但我仍然必须手动编写 getter,否则我的属性不会被初始化。我尝试手动合成这些属性,即使不再需要这些属性,但这并没有做到。
在下面的视图控制器中,我使用了motionTracker
永远不会初始化的属性。我的所有项目都有同样的问题,所以我知道这是我的误解。
#import "ViewController.h"
#import "TracksMotion.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *startRecording;
@property (weak, nonatomic) IBOutlet UIButton *stopRecording;
@property (strong, nonatomic) TracksMotion *motionTracker;
@end
@implementation ViewController
@synthesize motionTracker = _motionTracker;
- (void)startMyMotionDetect
{
[self.motionTracker startsTrackingMotion];
}
@end
该motionTracker
方法有一个公共 API,startsTrackingMotion
所以我不知道为什么这不起作用。
#import <Foundation/Foundation.h>
#import <CoreMotion/CoreMotion.h>
@interface TracksMotion : NSObject
- (void)startsTrackingMotion;
- (void)stopTrackingMotion;
@property (strong, nonatomic) CMMotionManager *motionManager;
@end