2014-12-04 21 views
1

我有一個視圖控制器,我有一個文本視圖,這是鍵盤是第一響應者,並且當這個視圖控制器加載時出現。如何創建一個動作方法來使選取器視圖出現?

我添加了一個配件視圖(帶按鈕)的文本視圖,並在視圖沒有負載作出self.myTextView.inputAccessoryView = self.accessoryView;,所以現在當鍵盤出現時,它有我的配件視圖上有一個按鈕....哦,我將配件視圖拖到場景中,因此它不會在視圖層次結構中。

現在我想添加一個選擇器視圖,我可以選擇一個倒計時時間,如「1小時」,「2時間」等

我如何使用我的附件副此按鈕可以火起來的拾起視圖?

我創建了一個從按鈕到視圖控制器的操作方法setTimerWasPressed,所以我猜這裏的代碼是這樣的,但是當我點擊setTimerWasPressed方法時,我應該怎麼做選擇器視圖來代替鍵盤。 ?

感謝

+0

你把picker作爲一個inmputView來代替鍵盤出現:[textView setInputView:picker]; – 2014-12-04 15:06:34

回答

0

我不明白的問題,但這裏是我的示例代碼:

@implementation CustomKeyboard 
- (void)didMoveToSuperview { 
    [super didMoveToSuperview]; 
    CGRect selfFrame = self.frame; 
    CGFloat buttonSize = 50; 
    self.button = [[UIButton alloc] initWithFrame:CGRectMake((selfFrame.size.width - buttonSize)/2, (selfFrame.size.height - buttonSize)/2, buttonSize, buttonSize)]; 
    self.button.backgroundColor = [UIColor greenColor]; 
    self.datePicker = [[UIDatePicker alloc] initWithFrame:self.frame]; 
    self.datePicker.backgroundColor = [UIColor grayColor]; 
    [self addSubview:self.button]; 
    [self.button addTarget:self action:@selector(showDataPicker:) forControlEvents:UIControlEventTouchUpInside]; 
} 
- (void)showDataPicker:(id)sender { 
    [self insertSubview:self.datePicker atIndex:self.subviews.count]; 
} 
@end 

希望它可以幫助你。

相關問題