在我的程序中,我試圖設置存儲在NSMutableArray中的對象的屬性「框架」。當我嘗試設置對象的框架時,我的程序通過消息'__ [NSCFNumber setFrame:]:發送到實例0x6a8d960的無法識別的選擇器接收到'SIGABRT'信號。我該如何解決?如何從一個NSMutableArray訪問一個對象的屬性
的for(int i = 0;我< [computerHand計數];我++) {
CardView* card = [computerHand objectAtIndex:i]; card.frame = CGRectMake(10+70*i, 340, 60, 85);
} computerHand的
聲明:
@property(retain)NSMutableArray * computerHand; computerHand
的
人口
-(void) addCardToHand:(NSMutableArray *)hand
{
[hand addObject:[cards objectAtIndex:0]];
NSLog(@"%@", [[cards objectAtIndex:0]class]);
[cards removeObjectAtIndex:0];
}
注意 - 在打印的NSLog '__NSCFNumber' 到控制檯。甲板人口
代碼
-(void) createDeck : (UIView *)view
{
cards = [[NSMutableArray alloc]initWithCapacity:52];
for (int i = 0; i <= 4; i++)
{
for(int j = 0; j <= 13; j++)
{
CardView* card = [[CardView alloc] initWithFrame:CGRectMake(view.center.x - 60/2, view.center.y - 85/2, 60, 85) value:j];
[cards addObject:card];
[view addSubview:card];
}
}
for(int i =0; i<= 52; i++)
{
NSLog(@"%@", [cards objectAtIndex:i]);
}
}
注:NSLog的命令正確打印CardView對象到控制檯,但隨後打印__NSCFNumber試圖從不同的作用域訪問它時。 任何幫助表示讚賞。
我們能不能看到你的代碼 – Mark 2012-03-15 12:58:54
你正試圖設置框架屬性爲NSNumber實例,檢查你的數組是否有所有有效的對象,多一點的代碼將很容易解決你的問題。 – iDroid 2012-03-15 13:00:28
@chiLLer,我該怎麼做呢? – Fitzy 2012-03-15 13:03:00