如何将 UIImagePickerController 推送到 UINavigationController 中?
我在我的程序中的 AppDelegate 中有以下编码,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
myList = [[List alloc] init];
mySettings = [[Settings alloc] init];
myCriteria = [[Criteria alloc] initWithStyle:UITableViewStyleGrouped];
first = [[UINavigationController alloc] initWithRootViewController:myList];
second = [[UINavigationController alloc] initWithRootViewController:mySettings];
third = [[UINavigationController alloc] initWithRootViewController:myCriteria];
myTabBar = [[UITabBarController alloc] init];
myTabBar.view.frame = CGRectMake(0,20,320,460);
UITabBarItem *first1 = [[UITabBarItem alloc] initWithTitle:@"List" image:[UIImage imageNamed:@"list.png"] tag:0];
UITabBarItem *second2 = [[UITabBarItem alloc] initWithTitle:@"My Profile" image:[UIImage imageNamed:@"settings.png"] tag:1];
UITabBarItem *third3 = [[UITabBarItem alloc] initWithTitle:@"Criteria" image:[UIImage imageNamed:@"Criteria.png"] tag:2];
UINavigationController *localNavigationController = [[UINavigationController alloc] initWithRootViewController:myTabBar];
first.tabBarItem = first1;
second.tabBarItem = second2;
third.tabBarItem = third3;
myControllerArray = [[NSArray alloc] initWithObjects:first, second, third, nil];
[myTabBar setViewControllers:myControllerArray];
[myTabBar setCustomizableViewControllers:myControllerArray];
[self.window addSubview:myTabBar.view];
// Add the view controller's view to the window and display.
// [self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
其中这三个是不同的类,现在我想使用相机和相册,所以当我在按钮目标上编写如下编码时,它不会工作
- (void) useCamera
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
NSLog(@"If is true");
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
// [self.navigationController pushViewController:imagePicker animated:YES];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self.tabBarController setCustomizableViewControllers:[[NSArray alloc]initWithObjects:imagePicker,self,nil]];
[self.tabBarController setViewControllers:[[NSArray alloc]initWithObjects:imagePicker,self,nil]];
//[self presentModalViewController:imagePicker animated:YES]; I tried
//[self.view addSubview:imagePicker.view]; I tried
//self.view=imagePicker.view; I tried
//[myScrollView addSubview:imagePicker]; I tried
//[myView addSubview:imagePicker]; I tried
[imagePicker release];
newMedia = YES;
}
}
我尝试了上述所有方法,但是他们没有工作并显示 UIImagePickerController,
我该怎么办......
现在如果有人不清楚我的问题,可以再次问我,
I have following coding in my Program, in AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
myList = [[List alloc] init];
mySettings = [[Settings alloc] init];
myCriteria = [[Criteria alloc] initWithStyle:UITableViewStyleGrouped];
first = [[UINavigationController alloc] initWithRootViewController:myList];
second = [[UINavigationController alloc] initWithRootViewController:mySettings];
third = [[UINavigationController alloc] initWithRootViewController:myCriteria];
myTabBar = [[UITabBarController alloc] init];
myTabBar.view.frame = CGRectMake(0,20,320,460);
UITabBarItem *first1 = [[UITabBarItem alloc] initWithTitle:@"List" image:[UIImage imageNamed:@"list.png"] tag:0];
UITabBarItem *second2 = [[UITabBarItem alloc] initWithTitle:@"My Profile" image:[UIImage imageNamed:@"settings.png"] tag:1];
UITabBarItem *third3 = [[UITabBarItem alloc] initWithTitle:@"Criteria" image:[UIImage imageNamed:@"Criteria.png"] tag:2];
UINavigationController *localNavigationController = [[UINavigationController alloc] initWithRootViewController:myTabBar];
first.tabBarItem = first1;
second.tabBarItem = second2;
third.tabBarItem = third3;
myControllerArray = [[NSArray alloc] initWithObjects:first, second, third, nil];
[myTabBar setViewControllers:myControllerArray];
[myTabBar setCustomizableViewControllers:myControllerArray];
[self.window addSubview:myTabBar.view];
// Add the view controller's view to the window and display.
// [self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
Where these three are different classes, now I want to use camera and album, so when I write coding as below on a button target, it won't work
- (void) useCamera
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
NSLog(@"If is true");
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
// [self.navigationController pushViewController:imagePicker animated:YES];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self.tabBarController setCustomizableViewControllers:[[NSArray alloc]initWithObjects:imagePicker,self,nil]];
[self.tabBarController setViewControllers:[[NSArray alloc]initWithObjects:imagePicker,self,nil]];
//[self presentModalViewController:imagePicker animated:YES]; I tried
//[self.view addSubview:imagePicker.view]; I tried
//self.view=imagePicker.view; I tried
//[myScrollView addSubview:imagePicker]; I tried
//[myView addSubview:imagePicker]; I tried
[imagePicker release];
newMedia = YES;
}
}
I tried all the above ways but they are not working and showing UIImagePickerController,
now what should I do
if anyone in not clear from my question, can ask me again.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
[self.view addSubview:imagePicker.cameraOverlayView]
怎么样另外,您是否尝试过向
self.view
添加任何其他视图?我想知道 imagePicker 是否已添加,但未加载,因为您添加到的视图未显示。What about
[self.view addSubview:imagePicker.cameraOverlayView]
Also, have you tried adding any other view to your
self.view
? I wonder if the imagePicker is being added, but is not loaded because the view you are adding it to is not being displayed.您是否尝试通过导航控制器之一呈现 imagePicker?
来自 参考
呈现用户界面通过调用当前活动视图控制器的
presentModalViewController:animated:
方法,将配置的图像选择器控制器作为新的视图控制器传递。在 iPad 上,您也可以使用弹出框来呈现用户界面,如initWithContentViewController:
和UIPopoverController
类参考中的“呈现和关闭弹出框”中所述。Did u try presenting the imagePicker through one of the navigation controllers?
From Reference
Present the user interface by calling the
presentModalViewController:animated:
method of the currently active view controller, passing your configured image picker controller as the new view controller. On iPad, you can alternatively present the user interface using a popover as described ininitWithContentViewController:
and “Presenting and Dismissing the Popover” inUIPopoverController
Class Reference.如果使用 GKImagePicker:
[self.view addSubview:self.imagePicker.imagePickerController.view];
If using GKImagePicker:
[self.view addSubview:self.imagePicker.imagePickerController.view];
你总是可以做:
为我工作
You can always do:
worked for me
您是否尝试通过 tabBarController 呈现
UIImagePickerController
(UITabBarController
继承自UIViewController
)?假设您为 AppDelegate 创建了一个单例,并且 tabBarController 是 AppController 的一个属性(为了方便起见,我在下面添加了单例的示例代码),代码将如下所示:AppController.h< /strong>
AppController.m
现在,在您的班级中,在 useCamera 方法上通过执行以下操作来调用 imagePicker:
祝您好运,编码愉快!
Did you try presenting the
UIImagePickerController
through the tabBarController (UITabBarController
inherits fromUIViewController
)? Assuming that you created a singleton for for your AppDelegate and that the tabBarController is a property of the AppController (for your convenience I added a sample code for the singleton below), the code would look something like this:AppController.h
AppController.m
Now in your class, on the useCamera method call the imagePicker by doing this:
Good luck and happy coding!