【发布时间】:2011-03-18 04:39:07
【问题描述】:
我的程序中有以下编码,在 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,
现在我该怎么办
如果有人对我的问题不清楚,可以再问我.....
【问题讨论】:
-
您是否尝试通过其中一个导航控制器展示 imagePicker?
-
[self.navigationController pushViewController:imagePicker animated:YES];,我做了这个,你在说这个吗?
-
试试 presentModalViewController
-
试试这个:[self presentModalViewController:imagePicker animated:YES]
-
@veer 你有没有使用 imagePickerviewControllerDelegate
标签: iphone uinavigationcontroller uiimagepickercontroller