0
期間的iOS指定初始化的問題我已經在我的頭文件中定義三個屬性如下:使用分配
@property (nonatomic,strong) NSNumber *forCount;
@property (nonatomic,strong) NSNumber *againstCount;
@property (nonatomic,strong) NSNumber *neutralCount;
在我的.m文件我已經被再合成:
@synthesize forCount = _forCount;
@synthesize againstCount = _againstCount;
@synthesize neutralCount = _neutralCount;
我指定的初始化被定義爲:
- (id)initWithCounts:(NSNumber *)forInitCount
againstCount:(NSNumber *)againstInitCount
neutralCount:(NSNumber *)neutralInitCount
{
NSLog(@"entering chartView initialization");
NSLog(@"chartView initialization. data being sent: forCount:%@, againstCount:%@, neutralCount: %@",forInitCount,againstInitCount,neutralInitCount);
if (self = [super init]) {
[self setForCount:forInitCount];
[self setAgainstCount:againstInitCount];
[self setNeutralCount:neutralInitCount];
}
NSLog(@"chartView initialization. forCount:%@, againstCount:%@, neutralCount: %@",self.forCount,self.againstCount,self.neutralCount);
[self setup];
return self;
}
我在安裝視圖中繪製圖表。
分配到性能似乎並不奏效。這是我的日誌是這樣的:
2013-11-21 03:13:20.897 testProj[4744:70b] entering chartView initialization
2013-11-21 03:13:20.897 testProj[4744:70b] chartView initialization. data being sent: forCount:10, againstCount:1, neutralCount: 5
2013-11-21 03:13:20.931 testProj[4744:70b] ChartView forCount: (null), againstCount: (null), neutralCount: (null)
2013-11-21 03:13:20.933 testProj[4744:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
任何想法,爲什麼性質仍然爲(null)
?
註釋掉[自設置]方法還導致同一(null)
分配。 - 因此,我可以排除出現的設置方法。
我打電話,像這樣的方法:
NSLog(@"chartViewAtIndex about to be called. forCount:%@, againstCount:%@ and neutralCount:%@",self.forVotes[index],self.againstVotes[index],self.neutralVotes[index]);
ChartView *chartView = [[ChartView alloc]initWithCounts:self.forVotes[index] againstCount:self.againstVotes[index] neutralCount:self.neutralVotes[index]];
日誌顯示:
2013-11-21 09:43:46.551 testProj[5284:70b] chartViewAtIndex about to be called. forCount:10, againstCount:1 and neutralCount:5
分配後break語句,該行的NSLog顯示之前的分配是否正確:
_forCount __NSCFNumber * (int)10 0xb0000000000000a2
_againstCount __NSCFNumber * (int)1 0xb000000000000012
_neutralCount __NSCFNumber * (int)5 0xb000000000000052
能否請您添加對'setup'方法的代碼?此外還調用方法'initWithCounts:againstCount:neutralCount:'的代碼? – 2013-11-21 08:34:14
有一些U R不告訴我們,我做了你的代碼的副本,它顯示了它的作用,告訴我們調用方法,你自定義對象的分配 – AntonijoDev
debug this 3'[self setForCount:forInitCount]; [self setAgainstCount:againstInitCount]; [自setNeutralCount:neutralInitCount]',看看他們中會發生什麼。回寫日誌。他們是否設置了'forCount,againstCount,neutralCount'的值? – Spire