iOS 6 UIPickerView导致崩溃

时间:2013-03-05 23:27:25

标签: ios ios6

我在iOS 6中遇到此异常,但无法找到原因。使用此库在表视图中选择日期: https://github.com/TimCinel/ActionSheetPicker

不确定是否是过早释放对象的库。

任何帮助都将不胜感激。

谢谢。

Exception Type EXC_BAD_ACCESS Code KERN_INVALID_ADDRESS at 0x5c8372ab
com.apple.main-thread Crashed
0    libobjc.A.dylib     objc_msgSend + 29
1    UIKit   -[UIApplication sendAction:to:from:forEvent:] + 72
2    UIKit   -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
3    UIKit   -[UIControl sendAction:to:forEvent:] + 44
4    UIKit   -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 502
5    UIKit   -[UIPickerView _sendSelectionChangedForComponent:] + 86
6    UIKit   -[UIPickerTableView _scrollingFinished] + 140
7    UIKit   -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 836
8    UIKit   -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 460
9    UIKit   -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 30
10   UIKit   -[UIScrollView(Static) _smoothScrollWithUpdateTime:] + 3362
11   QuartzCore  CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) + 160
12   QuartzCore  CA::Display::IOMFBDisplayLink::callback(__IOMobileFramebuffer*, unsigned long long, unsigned long long, unsigned long long, void*) + 64
13   IOMobileFramebuffer     IOMobileFramebufferVsyncNotifyFunc + 154
14   IOKit   IODispatchCalloutFromCFMessage + 192

1 个答案:

答案 0 :(得分:0)

只需编写以下代码

即可

注意:datePicker是我的UIDatePicker

-(IBAction)dateClicked:(id)sender
{
    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:nil
                                                      delegate:nil
                                             cancelButtonTitle:@"Done"
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];

    // Add the picker
    datePicker = [[UIDatePicker alloc] init];
    datePicker.datePickerMode = UIDatePickerModeDate;
    [datePicker addTarget:self
                   action:@selector(dateChange:)
         forControlEvents:UIControlEventValueChanged];
    [menu addSubview:datePicker];
    [menu showInView:self.view];        
    [menu setBounds:CGRectMake(0,0,320, 516)];
    [datePicker setFrame:CGRectMake(0, 85, 320, 216)];
    [self currentdate];
}

-(void)currentdate
{
    NSDate* date = [NSDate date];

    //Create the dateformatter object

    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];

    //Set the required date format

    [formatter setDateFormat:@"MMMM dd, yyyy"] ; //]@"yyyy-MM-dd HH:MM:SS"];

    //Get the string date

    NSString* str = [formatter stringFromDate:date];

    //Set in the lable
    dateULine.frame=CGRectMake(10, 122,150 , 2);

    [btnGetDate setTitle:str forState:UIControlStateNormal];
}

- (void)dateChange:(id)sender
{
    NSDate *selected = [datePicker date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MMMM dd, yyyy"];
    NSString *str = [formatter stringFromDate:selected];
    dateULine.frame=CGRectMake(10, 122,150 , 2);
    [btnGetDate setTitle:str forState:UIControlStateNormal];
}