//添加 我想在行动didrangebeacons开启后打开子视图。但是当它去那里时屏幕上没有任何视图。只是这个错误消息
以前的问题相同,但对我的问题没有帮助。我没有任何故事板或xib文件,只是清晰的编程。
BeaconViewController:UINavigationController上的0x155eb5b0:0x1559bfe0,其视图不在窗口层次结构中!
AppDelegate.m:
- (void) viewDidAppear {
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
DebugLog(@"");
NSLog(@"good1");
//and then access the variable by appDelegate.variable
// Оповещение о том, что надо включить Bluetooth, через минут, через 10 минут, через 8 часов, через неделю
[NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:900 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:28800 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:604800 target:self selector:@selector(timerCalled) userInfo:nil repeats:YES];
// Конец
//Set up Core Location Manager
self.coreLocation = [[CLLocationManager alloc] init];
_coreLocation.delegate = self;
// Load any previously registered notifications
[self loadNotificationRegions];
// Google Analytics
// Optional: automatically send uncaught exceptions to Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;
// Optional: set debug to YES for extra debugging information.
[GAI sharedInstance].debug = YES;
// Create tracker instance.
id <GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-42731391-1"];
// Check if the app needs to read the settings from file
NSString *transition = [[NSUserDefaults standardUserDefaults] stringForKey:@"transitionStyle"];
// Note: this will not work for boolean values as noted by bpapa below.
// If you use booleans, you should use objectForKey above and check for null
if (!transition) {
[self readFromSettingsFile];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
[[UIButton appearance] setTintColor:[UIColor whiteColor]];
// Remove the shadows of the bar
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
// Set the bar translucent
NSLog(@"good - start uinavig");
UINavigationController *navController = [[UINavigationController alloc] init];
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
navController.navigationBar.translucent = true;
NSLog(@"good - end uinavig");
// Background Color
if (IS_IOS_GREATER_THAN_OR_EQUAL_TO(@"7")) {
[[UINavigationBar appearance] setBarTintColor:NAVIGATIONS_VIEWS_BACKGROUND_COLOR];
} else {
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:NAVIGATIONS_VIEWS_BACKGROUND_COLOR];
}
// Buttons Color
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:255 / 255.0f green:255 / 255.0f blue:255 / 255.0f alpha:1]];
// Back button
if (IS_IOS_LESS_THAN(@"7")) {
UIImage *buttonBack30 = [[UIImage imageNamed:@"icon_back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 5)];
UIImage *buttonBack24 = [[UIImage imageNamed:@"icon_back_landscape.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 5)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24 forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -1.5) forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -2.0) forBarMetrics:UIBarMetricsLandscapePhone];
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setValue:[UIColor colorWithRed:(255 / 255.0f) green:(255 / 255.0f) blue:(255 / 255.0f) alpha:1.0f] forKey:UITextAttributeTextColor];
[attributes setValue:[UIColor clearColor] forKey:UITextAttributeTextShadowColor];
[attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.0, 0.0)] forKey:UITextAttributeTextShadowOffset];
[attributes setValue:[UIFont fontWithName:@"HelveticaNeue" size:16.0f] forKey:UITextAttributeFont];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
}
// Title Color and Font
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:@"HelveticaNeue-Bold" size:17.0], UITextAttributeFont, nil]];
self.viewController = [[ViewController alloc] init];
navController.viewControllers = [NSArray arrayWithObject:self.viewController];
//
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
并致电:
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)beaconRegion
{
blabla
if(blabla)
{
NSLog(@"good - testing - 03.5");
BeaconViewController* room = [[BeaconViewController alloc] init];
[self.window.rootViewController presentViewController:room
animated:YES
completion:nil];
completion:nil];
region.helloMessage = @"привет";
}
BeaconViewController.m
#import "BeaconViewController.h"
#import "PageView.h"
@implementation BeaconViewController
{
NSUInteger _numPages;
}
- (void) vidDidAppear {
}
- (void)viewDidLoad
{
[super viewDidLoad];
_numPages = 2;
self.pagingScrollView.previewInsets = UIEdgeInsetsMake(0.0, 50.0, 0.0, 50.0);
[self.pagingScrollView reloadPages];
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = _numPages;
}
- (void)viewDidAppear:(BOOL)animated {
}
- (void)didReceiveMemoryWarning
{
[self.pagingScrollView didReceiveMemoryWarning];
}
#pragma mark - Actions
- (IBAction)pageTurn
{
[self.pagingScrollView selectPageAtIndex:self.pageControl.currentPage animated:YES];
}
#pragma mark - View Controller Rotation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.pagingScrollView beforeRotation];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self.pagingScrollView afterRotation];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)theScrollView
{
self.pageControl.currentPage = [self.pagingScrollView indexOfSelectedPage];
[self.pagingScrollView scrollViewDidScroll];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)theScrollView
{
if ([self.pagingScrollView indexOfSelectedPage] == _numPages - 1)
{
_numPages++;
[self.pagingScrollView reloadPages];
self.pageControl.numberOfPages = _numPages;
}
}
#pragma mark - MHPagingScrollViewDelegate
- (NSUInteger)numberOfPagesInPagingScrollView:(MHPagingScrollView *)pagingScrollView
{
return _numPages;
}
- (UIView *)pagingScrollView:(MHPagingScrollView *)thePagingScrollView pageForIndex:(NSUInteger)index
{
PageView *pageView = (PageView *)[thePagingScrollView dequeueReusablePage];
if (pageView == nil)
pageView = [[PageView alloc] init];
[pageView setPageIndex:index];
return pageView;
}
@end
答案 0 :(得分:0)
替换
UINavigationController *navController = [[UINavigationController alloc] init];
与
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController...
可能会解决问题
在一个不相关的笔记上杀死菊花链就像这样 - (void)vidDidAppear {
} 在路上遇到麻烦,考虑清理你的代码。一团糟 甚至通过stackoverflow标准