2013-11-28 3 views
0

내 키보드 위에 UIView/Toolbar을 포함 시키려고했지만 행운이 없었습니다. 도구 모음을 추가 할 때 스크램블되어 있으므로 UIView에 넣어야하지만 UIView은 키보드 위에 나타나지 않습니다. 아래 코드 :inputaccessoryview가 표시되지 않음 (StoryBoard)

내 헤더 :

@property (nonatomic, Strong) IBOutlet UITextView *textView; 
@property (nonatomic, strong) IBOutlet UIToolbar *TitleBar; 
@property (nonatomic, weak) IBOutlet UIView *AddView; 

ViewDidLoad :

- (void)viewDidLoad 
{  
    // observe keyboard hide and show notifications to resize the text view appropriately 
    /*[[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillShow:) 
               name:UIKeyboardWillShowNotification 
               object:nil]; 
    */ 

    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { 
     // iOS 7 
     [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)]; 
    } else { 
     // iOS 6 
     [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; 
    } 

    self.attributionTitle.delegate = self; 
    self.attribution.delegate = self; 
    textView.scrollEnabled = YES; 
    // quoteText.layer.borderColor = [UIColor blackColor].CGColor; 
    // quoteText.layer.borderWidth = 1.0f; 

    // textView.delegate = self; // code or in IB 

    [textView becomeFirstResponder]; 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

textViewDidBeginEditing : enter image description here

:

여기
-(void)textViewDidBeginEditing:(UITextView *)textView 
{ 
    self.textView.inputAccessoryView = self.AddView; 
} 

가 연결되어있는 UIView을 보여주는 것입니다

답변

1

textView.inputAccessoryView = AddView;을 추가 한 다음 내 스토리 보드에서보기를 삭제하고 다시 작성했습니다. 마지막으로 하단 검은 막대에 UIView을 추가했습니다.

+0

하단 검은 막대에보기를 추가한다는 것은 무엇을 의미합니까? 스토리 보드에서 뷰를 실제로 소유하고있는 뷰 컨트롤러에 배치되지 않은 뷰를 정의 할 수 있습니까? 이러한보기는 스토리 보드에 시각적으로 표시되며 부모보기 컨트롤러와 어느 정도 겹쳐서 연결됩니까? – devios1

0

inputAccessoryViewtextViewDidBeginEditing에 추가하는 것은 너무 늦었을 것입니다. 입력 액세서리보기는 예를 들어 viewDidLoad 메소드에서 설정해야합니다.

해보십시오 같은 :

-(void)viewDidLoad{ 
    [super viewDidLoad]; 

UIView 

    myTextField.inputAccessoryView = [self accessoryViewWithPreviousEnabled:NO nextEnabled:YES]; 

    // more stuff as required... 
} 

그리고 이전/다음 버튼을 만드는 방법 (당신은 버튼에 자신의 이미지를 제공해야하고, previousAccessoryViewButtonTapped:previousAccessoryViewButtonTapped: 방법을 구현하는 것이다). 이전 및/또는 다음 버튼을 사용할 수 있는지 나타내는 데 두 개의 BOOL 매개 변수가 필요합니다.

#pragma mark - Accessory view methods 

-(UIView *)accessoryViewWithPreviousEnabled:(BOOL)previousEnabled nextEnabled:(BOOL)nextEnabled{ 
    previousButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    previousButton.frame = CGRectMake(10, 2, 60, 30); 
    [previousButton setImage:[UIImage imageNamed:PREVIOUS_BUTTON] forState:UIControlStateNormal]; 
    previousButton.enabled = previousEnabled; 
    [previousButton addTarget:self action:@selector(previousAccessoryViewButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; 

    nextButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    nextButton.frame = CGRectMake(80, 2, 60, 30); 
    [nextButton setImage:[UIImage imageNamed:NEXT_BUTTON] forState:UIControlStateNormal]; 
    nextButton.enabled = nextEnabled; 
    [nextButton addTarget:self action:@selector(nextAccessoryViewButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; 

    UIView *transparentBlackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 34)]; 
    transparentBlackView.backgroundColor = [UIColor colorWithRed:0.f green:0.f blue:0.f alpha:0.6f]; 

    UIView *accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 34)]; 
    [accessoryView addSubview:transparentBlackView]; 
    [accessoryView addSubview:previousButton]; 
    [accessoryView addSubview:nextButton]; 

    return accessoryView; 
} 

이 방법은 iPad 용으로 하드 코딩되어 있습니다. iPhone 용으로 변경해야합니다.

+0

스토리 보드에 설치할 수 있습니까? – user2977529

0

self.AddView이 이미 인터페이스에 있습니다 (스토리 보드에 넣기 때문에). 한 번에 두 장소에있을 수 없습니다.

+0

그럼 어떻게 수정하겠습니까? 하드 코딩해야하나요? @matt – user2977529

관련 문제