gpt4 book ai didi

objective-c - copyWithZone错误-[DataObject setECGCount:]:无法识别的选择器已发送到实例

转载 作者:行者123 更新时间:2023-12-02 07:28:55 24 4
gpt4 key购买 nike

我的应用程序崩溃并出现以下错误:

-[Data Object set ECGCount:]: unrecognized selector sent to instance 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:]: unrecognized selector sent to instance 0x281671ad0

2020-08-20 11:58:57.885908+0100 PulseGuardian[3927:2317144] *Terminating app due to uncaught exception'NSInvalidArgumentException', reason: '-[DataObject setECGCount:]:unrecognized selector sent to instance 0x281671ad0'


我该如何解决这个问题?

最佳答案

正如@Larme在评论中指出的那样,我在
DataObject.m
代码如下:

[copy setECGCount:self.heartrate];
什么时候应该阅读:
[copy setHeartrate:self.heartrate];
更改代码后,应用程序将按预期工作。我代表自己犯了愚蠢的错误,但会留在这里,以防将来对其他人有帮助。

关于objective-c - copyWithZone错误-[DataObject setECGCount:]:无法识别的选择器已发送到实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63504174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com