Iphone UINavigation控制器UIViewController和UItoolbar作为子视图问题
嘿,伙计们,我正试图离开增强现实系统,转到导航控制器的下一个视图控制器 代码来自ARKit demo,我刚刚以编程方式添加了一个UIToolbar作为子视图,其中包含一个操作按钮。我希望此按钮指向现有导航控制器的下一个视图控制器。动作takePicture:在收到NSLog消息时执行,但未添加新的viewcontroller 这是ARGeoViewController.h的代码Iphone UINavigation控制器UIViewController和UItoolbar作为子视图问题,iphone,uinavigationcontroller,subview,uitoolbar,Iphone,Uinavigationcontroller,Subview,Uitoolbar,嘿,伙计们,我正试图离开增强现实系统,转到导航控制器的下一个视图控制器 代码来自ARKit demo,我刚刚以编程方式添加了一个UIToolbar作为子视图,其中包含一个操作按钮。我希望此按钮指向现有导航控制器的下一个视图控制器。动作takePicture:在收到NSLog消息时执行,但未添加新的viewcontroller 这是ARGeoViewController.h的代码 #import <Foundation/Foundation.h> #import "ARViewCon
#import <Foundation/Foundation.h>
#import "ARViewController.h"
#import "AfterARViewController.h"
@interface ARGeoViewController : ARViewController {
CLLocation *centerLocation;
AfterARViewController *afterARViewController;
}
@property (nonatomic, retain) CLLocation *centerLocation;
- (IBAction)takePicture:(id)sender;
@property (nonatomic, retain) AfterARViewController *afterARViewController;
@end
非常感谢我对ARKit没有经验,但是cameraController是导航控制器堆栈的一部分吗?当你释放它的时候,你可能会扔掉东西。作为测试,试着注释掉释放cameraController的代码行,看看它是否影响了这一点 另外,FWIW我希望您用来设置工具栏的代码在viewDidLoad中,而不是在ViewDidDisplay中
#import "ARGeoViewController.h"
#import "ARGeoCoordinate.h"
#import "ARViewController.h"
@implementation ARGeoViewController
@synthesize centerLocation;
@synthesize afterARViewController;
- (void)setCenterLocation:(CLLocation *)newLocation {
[centerLocation release];
centerLocation = [newLocation retain];
for (ARGeoCoordinate *geoLocation in self.coordinates) {
if ([geoLocation isKindOfClass:[ARGeoCoordinate class]]) {
[geoLocation calibrateUsingOrigin:centerLocation];
if (geoLocation.radialDistance > self.maximumScaleDistance) {
self.maximumScaleDistance = geoLocation.radialDistance;
}
}
}
}
-(void)viewWillAppear:(BOOL)animated{
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
// create a bordered style button with custom title
UIBarButtonItem *playItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:@selector(takePicture:)] autorelease];
NSArray *items = [NSArray arrayWithObjects:
playItem,
nil];
toolbar.items = items;
// size up the toolbar and set its frame
// please not that it will work only for views without Navigation toolbars.
[toolbar sizeToFit];
CGFloat toolbarHeight = [toolbar frame].size.height;
CGRect mainViewBounds = self.view.bounds;
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
[self.view addSubview:toolbar];
}
- (IBAction)takePicture:(id)sender
{
NSLog(@"takepicture");
if(self.afterARViewController == nil)
{
AfterARViewController *afterARController = [[AfterARViewController alloc]
initWithNibName:@"AfterARViewController" bundle:[NSBundle mainBundle]];
self.afterARViewController = afterARController;
[afterARController release];
[cameraController release];
}
[self.navigationController pushViewController:self.afterARViewController animated:YES];
}
@end