2011-09-08 14 views
0

Appleのコード例を使用して、特定のUITableViewCellが選択されたときにUIDatePickerを表示しています。UITablePickerはUITableViewCellの後に表示されません。

この動作を変更するにはどうすればよいですか?

Messed up view

私のコードは:私は与えられた絵から見

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

if(indexPath.section == 5) { 
    //Date Picker 
    UITableViewCell *targetCell = [tableView cellForRowAtIndexPath:indexPath]; 
    self.pickerView.date = [self.dateFormatter dateFromString:targetCell.textLabel.text]; 
    if (self.pickerView.superview == nil) 
    { 
     [self.view.window addSubview: self.pickerView]; 

     // size up the picker view to our screen and compute the start/end frame origin for our slide up 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; 

     // compute the 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]; 

    } 

} 


} 
+0

この行を使用する理由 [tableView deselectRowAtIndexPath:indexPath animated:YES]; – Scar

+0

私の他のセルはテキストフィールドなので、セルは常に強調表示したくありません。しかし、この行は違いはありません。 – jussi

+0

セルのハイライトを無効にするには、この適切性を使用する必要があります '[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; セクション番号5を選択してください。 – Scar

答えて

0

を、あなたはpickerRectのためのフレームを設定する必要はありません。ただ、向きの変更

self.picker.autoresizingMask = UIViewAutoresizingFlexibleWidth | 
UIViewAutoresizingFlexibleTopMargin; 

あなたがやったとしてあなたは、その枠を設定することにより、ピッカービューのサイズを強制することができますが、以下のように、pickerViewが、それと共に回転すべきであることをアプリに伝える必要があります。 UISplitViewControllerで作業しているので、pickerViewはdetail ViewControllerのサブビューでなければなりません。self.view.windowではありません。また、this linkで提供されているサンプルを見て、あなたが作っている他のミスを見てください。

0

、あなたが上向きに、画面の下部からUIPickerViewをスライドしようとしているということです。

もしそうなら、フレームを設定していないと思います。

View and Window Architectureに示すように、座標系の原点は左上隅です。

が、私はこのような何かwhould:あなたが提供したコードは、あなたのdetailのViewControllerであると仮定すると、

CGRect pickerFrame = pickerView.frame; 
pickerFrame.origin.x = leftTableViewWidth; 
pickerFrame.origin.y = screenFrame.size.height + pickerFrame.size.height; 
pickerView.frame = pickerFrame; 
// begin animation here 
pickerFrame.origin.y += pickerFrame.size.height; 
// commit animation 
関連する問題