我已經看了很多文章來幫助我,但未能找到答案......更換右側的UIBarButtonItem與「完成」按鈕
我想,當鍵盤來代替我的右邊欄按鈕是一個「完成」按鈕激活,然後在編輯完成後將其重新放回...
我已經有一個正確的欄按鈕,它是一個分段控件,並在視圖加載時設置。我不確定一旦它創建後是否可以切換欄按鈕?
下面是一些屏幕截圖...
想向後退/前進按鈕更改爲完成按鈕時,鍵盤會出現
以下是我的代碼觸發鍵盤顯示時...代碼執行但按鈕不顯示...
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
// Replace the Right Navigation Button with done button
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(doneEditing)];
self.navigationItem.rightBarButtonItem = doneButton;
// Slide up the view
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
// Move the view .... Note need to calculate this based on the size of the keyboard !!
rect.origin.y -= 120.0f;
rect.size.height += 120.f;
self.view.frame = rect;
// Resize the text view .... Note need to calculate this based on screen size !!
CGSize frameSize = self.reviewTextView.frame.size;
CGPoint framePos = self.reviewTextView.frame.origin;
[self.reviewTextView setFrame:CGRectMake(framePos.x, framePos.y, frameSize.width, 200.0f)];
[UIView commitAnimations];
return YES;
}
以下是當視圖被加載
//set up the segmented control and add it to the nav bar rightBartButtonItem
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"\U000025C0\U0000FE0E Prev", @"Next \U000025B6\U0000FE0E", nil]];
UIBarButtonItem * segmentControlButton = [[UIBarButtonItem alloc] initWithCustomView:segmentControl];
[segmentControl setBackgroundColor:[UIColor clearColor]];
segmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentControl.frame = CGRectMake(0, 0, 120, 30);
[segmentControl setMomentary:YES];
[segmentControl addTarget:self
action:@selector(onSegmentChanged:)
forControlEvents:UIControlEventValueChanged];
self.navigationItem.rightBarButtonItem = segmentControlButton;
您是如何在第一個地方設置prev/next按鈕的? – micantox
添加上面的代碼以顯示在加載視圖時如何設置上一個/下一個按鈕。 – rs2000
然後我不明白。我無法重現該問題。使用完全相同的代碼,它一切正常。問題必須放在其他地方.. – micantox