2010-12-17 5 views
1

나는 textField를 게시 할 툴바가 있습니다. 다음 코드로 시도하지만 작동하지 않습니다.툴바에 텍스트 필드를 추가하는 방법

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStyleBordered target:self action:@selector(action:)]; 

UITextField *customItem1 = [[UITextField alloc] init]; 

    NSArray *items = [NSArray arrayWithObjects: customItem, customItem1, nil]; 
[self setToolbarItems:items animated:YES]; 

답변

4

툴바 항목은 모두 UIBarButtonItem이어야합니다.

UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithCustomView:view]; 
//view is the embedded view, in your case a UITextField 
+0

잘하지만보기의 UITextField를 변환하는 방법 임 확실하지 같습니다 : 다른 것을 표시하기 위해, 당신이 항목에 대한 전망을 포함 지금 충돌하지 않는 S, 그것은 단지 지금 상점 버튼을 표시합니다 – k20

+2

텍스트 필드 프레임을 설정하고이 텍스트 필드를 인수로 initWithCustomView와 함께 추가하십시오. 타입 캐스팅에 대해 걱정하지 마십시오. – sudesh

+0

대단히 감사합니다. – k20

관련 문제