1

我有这段代码,它在用户选择文本字段以显示日期选择器时触发的操作中:

    pickerViewPopup = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

    pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
    pickerView.datePickerMode = UIDatePickerModeDateAndTime;
    pickerView.hidden = NO;
    pickerView.date = [NSDate date];

    UIToolbar *pickerToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
    [pickerToolbar sizeToFit];

    NSMutableArray *barItems = [[NSMutableArray alloc] init];

    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];

    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonPressed:)];
    [barItems addObject:doneBtn];

    [pickerToolbar setItems:barItems animated:YES];

    [pickerViewPopup addSubview:pickerToolbar];
    [pickerViewPopup addSubview:pickerView];
    [pickerViewPopup showFromTabBar:self.tabBarController.tabBar];
    [pickerViewPopup setBounds:CGRectMake(0,0,320, 500)];

我在带有用于导航的标签栏的应用程序中使用此代码。现在我想在没有它的应用程序中使用它,但是当进程到达时[pickerViewPopup showFromTabBar:self.tabBarController.tabBar];它会崩溃。

关于如何修复它的任何想法?

4

1 回答 1

2

使用以下之一,

– showFromToolbar:
– showInView:
– showFromBarButtonItem:animated:
– showFromRect:inView:animated:

例如:-

[pickerViewPopup showFromToolbar:pickerToolbar];

问题是您没有标签栏,并且您正在尝试访问标签栏对象以从中显示选择器。由于 tabbar 对你来说是 nil ,所以它会崩溃。

有关更多详细信息,请查看苹果文档。

于 2012-11-29T19:50:09.010 回答