【问题标题】:UIDatePicker not showing up in static tableView on iPadUIDatePicker 未显示在 iPad 上的静态 tableView 中
【发布时间】:2012-03-23 21:25:53
【问题描述】:

我有一个表格视图以模态显示,其中有几个静态单元格显示开始日期和结束日期。

当我点击它们时,我希望 UIDatePicker 出现。目前,当我单击该行时没有任何反应。我错过了什么?

这是我的 didSelectRowAtIndexPath :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {   
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    self.pickerView.date = [self.dateFormatter dateFromString:selectedCell.detailTextLabel.text];

    //  check if date picker already on screen
    if (self.pickerView.superview == nil) {
        [self.view.window addSubview:self.pickerView];

        // size up the picker view to fit our screen and compute animation
        //
        //compute the start frame
        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
        CGSize pickerSize = [self.pickerView sizeThatFits:CGSizeZero];
        CGRect startRect = CGRectMake(0.0, 
                                       screenRect.origin.y + screenRect.size.height, 
                                       pickerSize.width, 
                                       pickerSize.height
                                       );
        self.pickerView.frame = startRect;

        //computer end frame
        CGRect pickerRect = CGRectMake(0.0, 
                                       screenRect.origin.y + screenRect.size.height - pickerSize.height, 
                                       pickerSize.width, 
                                       pickerSize.height
                                       );
        // start the slide up animation
        [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.3];

            // we need to perform some post operations after the animation is complete
            [UIView setAnimationDelegate:self];

            self.pickerView.frame = pickerRect;

            // shrink the table vertical size to make room for the date picker
            CGRect newFrame = self.tableView.frame;
            newFrame.size.height -= self.pickerView.frame.size.height;
            self.tableView.frame = newFrame;
        [UIView commitAnimations];

        // add the "Done" button to the nav bar
        self.navigationItem.rightBarButtonItem = self.doneButton;
    } }

【问题讨论】:

    标签: objective-c ios ipad uitableview uidatepicker


    【解决方案1】:

    愚蠢的错误。我在头文件中将 pickerView 属性设置为弱而不是强:

    这个:

    @property (weak, nonatomic) IBOutlet UIDatePicker *pickerView;
    

    实际上应该是这样的:

     @property (strong, nonatomic) IBOutlet UIDatePicker *pickerView;
    

    【讨论】:

    • 我认为这个答案有错字。你两次都很虚弱:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多