2014-07-25 1 views
0

나는 AppDelegate에 내 하단에 메뉴를 추가 :아이폰 OS 글로벌 메뉴

- (void)addBottomMenu 
{ 
    BottomMenu *bottomMenu = [[BottomMenu alloc] initWithFrame:CGRectMake(0, [ScreenHelper getHeightOfScreen] - 70, 320, 70)]; 
    bottomMenu.delegate = self; 
    [[[[UIApplication sharedApplication] delegate] window] addSubview:bottomMenu]; 
} 

나는 갤러리에서 카메라 걸릴 사진 걸릴 사진에 대한 2 개 메뉴 버튼이있다. 이 버튼은 전 세계 모든 컨트롤러에서 동일하게 작동합니다. 갤러리 (또는 카메라)를 표시하고 사용자가 사진을 선택 (또는 찍기) 한 후에 동일한 컨트롤러로 이동하여 이미지를 표시하도록 작동해야합니다. 컨트롤러에서 다음 코드 줄을 추가합니다.

- (void)photoButtonTapped 
{ 
    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 

    [self presentViewController:picker animated:YES completion:NULL]; 
} 

#pragma mark Image Picker delegates 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    imageOfReceipt = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
    [self performSegueWithIdentifier:@"detailReceiptSegue" sender:self]; 
} 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 
} 

... 여기서 photoButtonTapped은 대리인의 것입니다. 작동 중입니다 (컨트롤러에서 하단 메뉴를 시도 할 때, 지금 AppDelegate에 추가했을 때가 아닙니다). AppDelegate에서보기 컨트롤러를 표시하는 데 문제가 있습니다 (이유는 알지만이 방법을 무시하는 방법을 모르겠습니다). AppDelegate에서 작동하도록해야합니다. 모든 컨트롤러에 이것을 복제하고 AppDelegate의 BottomMenu에서 델리게이트를 변경하고 싶지 않습니다. 글로벌화가 가능한가?

+0

baseViewController를 만들고 그 안에 모든 이미지 파이킹 작업을 추가하고 모든 클래스에서 baseViewController를 가져옵니다. 그것은 당신의 문제를 해결할 수 있습니다. –

답변

1

예, 그렇습니다. 전화하지 왜 :

[self.navigationController.topViewController presentViewController:picker 
                  animated:YES 
                 completion:NULL]; 

를 AppDelegate에에는있는 navigationController 속성이없는 경우, 다른 방법으로는 현재 제시된보기 컨트롤러를 얻을하려고합니다. 예를 들어, self.window.rootViewController를 시도해보십시오. 그리고 아마 당신은 segues를 사용하지 않아야합니다.

+1

나는이 솔루션과 Ashish Kakkad의 의견에 대해 생각하고 있었고 나는 당신의 솔루션을 선택했다. 두 가지 솔루션 모두 장단점이 있으며 내 프로젝트에는이 기능이 더 유용합니다. 감사합니다 –

+0

당신을 환영합니다! – kelin