如何解决copyWithZone错误-[DataObject setECGCount:]:无法识别的选择器已发送到实例
我的应用程序崩溃并出现以下错误:
-[数据对象集ECGCount:]:无法识别的选择器已发送到实例0x281671ad0
我试图在我的主要viewController类之间传递数据到DataObject类,然后将这些信息最终传递给IntervalGraph类。
我正在使用copyWithZone进行此操作,但是卡住了。
这是 viewContoller.h 类:
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface ViewController : UIViewController<CPTPlotDataSource>
@property (nonatomic,assign) int eCGCount;
@property (nonatomic,assign) int eCGheartRate;
@end
以及 viewController.m
中的相关代码@property (nonatomic) DataObject *maxRecordedHR,*minRecordedHR,*currentData,*continuousData,*seizureData;
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter addObserver:self
selector:@selector(sensorDataUpdated)
name:@"LYRDeviceCommunicatorDataUpdated"
object:nil];
self.rollingAverageHRArray = [[NSMutableArray alloc]initWithCapacity:180];
self.currentData = [[DataObject alloc]init];
self.continuousData = [[DataObject alloc]init];
self.seizureData = [[DataObject alloc]init];
}
//fired by a 1 second timer
-(void)startIntervalGraph {
[self sensorDataUpdated];
if (self.currentData.heartrate == 0 )
{NSLog(@"No data");
} else {
self.rollingAverageLabel.text = [NSString stringWithFormat:@"rolling 3 min average %1.1f",self.currentData.rollingaverageheartrate];
[self.intervalGraph addDataObject:self.currentData]; // something wrong here
[self.intervalGraph updateGraph];
NSLog(@"Updating Interval Graph");
}
}
-(void) sensorDataUpdated {
//Heart Rate
self.currentData.heartrate = self.eCGheartRate;
NSLog(@"Current Data %d",self.currentData.heartrate);
}
-(void)setECGCount:(int)eCGCount
{
self.eCGheartRate = (int) eCGCount;
eCGCount = self.eCGCount;
NSLog(@"eCGCount %d",self.eCGCount);
}
然后是 DataObject.h 类
#import <Foundation/Foundation.h>
@interface DataObject : NSObject <NSCopying>
@property int heartrate;
@property float rollingaverageheartrate;
@property float rrinterval;
@property NSTimeInterval occurrence;
@property NSInteger minHRsetting;
@property NSInteger maxHRsetting;
@property int alarmtripped;
@end
和 DataObject.m
#import "DataObject.h"
#import "CRPC_300SDK.h"
#import "ViewController.h"
@implementation DataObject
- (id)copyWithZone:(NSZone *)zone
{
id copy = class alloc] init];
if (copy) {
// Set primitives
[copy setECGCount:self.heartrate]; //THIS IS WHERE THE CRASH OCCURS.
//[copy setRrinterval:self.rrinterval];
[copy setRollingaverageheartrate:self.rollingaverageheartrate];
[copy setOccurrence:self.occurrence];
[copy setMinHRsetting:self.minHRsetting];
[copy setMaxHRsetting:self.maxHRsetting];
[copy setAlarmtripped:self.alarmtripped];
}
return copy;
}
当我打电话
[copy setECGCOUNT:self.heartrate];
该应用程序崩溃并出现以下错误:
2020-08-20 11:58:57.884543 + 0100 PulseGuardian [3927:2317144] -[DataObject setECGCount:]:无法识别的选择器已发送到实例0x281671ad0
2020-08-20 11:58:57.885908 + 0100 PulseGuardian [3927:2317144] * 由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[DataObject setECGCount:]: 无法识别的选择器已发送到实例0x281671ad0'
我该如何解决此问题?
解决方法
@Larme在评论中指出,我在
中引用了错误的方法DataObject.m
代码如下:
[copy setECGCount:self.heartrate];
何时应阅读:
[copy setHeartrate:self.heartrate];
代码一旦更改,应用程序就可以正常工作。代表我的愚蠢错误,但会留在这里,以防将来对其他人有帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。