0

我设置UIDatePicker了一个 cocos2d 场景。(希望它是对的)它工作得很好,直到我必须选择一个日期,所以我滚动选择器,然后它停止的那一刻,它崩溃了,它甚至不调用选择器方法。

CGRect pickerFrame = CGRectMake(0,250,0,0);

UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[myPicker addTarget:self action:@selector(pickerChanged:) 
        forControlEvents:UIControlEventValueChanged];

//[self.view addSubview:myPicker];
[[[CCDirector sharedDirector] view] addSubview:myPicker];
[myPicker release];


- (void)pickerChanged:(id)sender
{
    NSLog(@"value: %@",[sender date]);

}

顺便说一句,我是否正确地将选择器添加到 cocos2d 场景中?

4

2 回答 2

1

It crashes when the picker try to call your method, but the target ( self) may have been deallocated, so you should get an EXC_BAD_ACCESS.

于 2012-08-30T06:45:17.100 回答
0

date 是一个属性而不是一个函数......在这种情况下,sender 是一个 DatePicker。下面的代码应该可以工作!

-(void)pickerChanged:(UIDatePicker*) datePicker{
    NSLog(@"value: %@",datePicker.date);
}
于 2012-08-29T11:45:46.920 回答