2014-10-08 3 views
1

UINavigationController 내에 UITableView가 있습니다. 테이블 셀과 함께 움직이지 않는 화면 아래쪽에 도구 모음을 만들려면 UIView를 하위보기로 탐색 막대에 추가했습니다.UINavigationBar 및 터치 이벤트의 하위 뷰에 프로그래밍 방식으로 UIButton 추가하기

이 UIView를 추가하기 위해 프로그래밍 방식으로 UIButton을 생성합니다. 선택기를 추가했지만 등록하지 않았고 함수를 호출하여 (sendMessage) 설정했습니다.

어떤 아이디어?

self.sendBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width,100)]; 
self.sendBar.backgroundColor = cloudBlue; 
UIButton *sendButton = [[UIButton alloc] initWithFrame:CGRectMake(0,0,50,50)]; 
sendButton.backgroundColor = [UIColor blackColor]; 
[sendButton addTarget:self action:@selector(sendMessage) forControlEvents:UIControlEventTouchUpInside]; 
[self.navigationController.navigationBar addSubview:self.sendBar]; 
[self.sendBar addSubview:sendButton]; 

답변

1

나는 당신이 "sendBar"의 하위 뷰 같은 버튼을 추가하지만, 기본보기에서 선택을 참조하고 있다는 사실과 함께 할 수있는 뭔가가 의심. 여기에서 할 수있는 두 가지 일이 있습니다.

1 : sendButton을 하위보기로 포함하는 UIView의 사용자 정의 하위 클래스로 sendBar를 만듭니다. 그런 다음 sendBar에 대한 대리자를 만들고 sendBar 구현에서 기본보기 내에서 트리거되도록합니다.

2 : sendButton을 부모보기에 직접 추가하고 sendBar가 아닌 하위보기로 추가하십시오. 또한

UIButton *sendButton = [[UIButton alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height,50,50)]; 
sendButton.backgroundColor = [UIColor blackColor]; 
[sendButton addTarget:self action:@selector(sendMessage) forControlEvents:UIControlEventTouchUpInside]; 
[self.navigationController.navigationBar addSubview:self.sendBar]; 
[self.sendBar addSubview:sendButton]; 
[self.view addSubview:sendButton]; 

, 당신은 아마 괜찮 단지 self.view하는 sendBar를 추가 할 것입니다 그리고 당신은 당신의있는 tableView의 상단에 표시를하고자하는 경우 self.navigationController.navigationBar하지; 하지만 당신이하려는 일의 전체 범위를 알지 못합니다.

0

sendBar 프레임은 옳지 않다, 수를 설정하려고 :

CGRectMake(0, 0, self.view.frame.size.width,100) 

sendBar은 일반적으로 (64)의 높이가 내비게이션 바의 하위 뷰, 변경할 수 있도록 높이 100 (64)

0
UIButton *right = [[UIButton alloc]initWithFrame:CGRectMake(0, 0,25, 20)]; 
[right setBackgroundColor:[UIColor redColor]]; 
[right setBackgroundImage:[UIImage imageNamed:@"imgPhoto"] forState:UIControlStateNormal]; 
[right addTarget:self action:@selector(showRightClicked) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *buttonItem1 = [[UIBarButtonItem alloc]initWithCustomView:right]; 
self.navigationItem.leftBarButtonItem = buttonItem1; 

// 오른쪽 막대 버튼으로 설정하려면 self.navigationItem.rightBarButtonItem = buttonItem1

관련 문제