我說我的底部菜單中的AppDelegate:有照片和畫廊的按鈕iOS的全局菜單
- (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中的委託。是否有可能做到全球?
創建一個baseViewController並添加所有圖像piking工作,並在所有類中導入baseViewController。可以解決你的問題。 –