I've subclass UINavigationController like this:
#implementation BaseNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count) {
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
}
And also I've a subclass of UIViewController like this:
#implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBarController.tabBar.translucent = NO;
self.navigationController.navigationBar.translucent = NO;
self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
All my view controller are inheriting the baseViewController and all my navigation controller are inheriting the baseNavigationController.
UITabBarViewController -> BaseNavigationController -> BaseViewController
The issue is sometimes when my application is back from background and tap a cell (UITableView or UICollectionView), pushViewController do not work, and the app get stuck.Or sometimes only navigation bar pushed to next view controller,shows next view controller's title and the app also get stuck.The next view controller's viewDidLoad method is called.
I've worried for a week and I do not know why this is happened,so please help me to fix this odd issue.
Not 100% get this issue ,only sometimes.Thank you.
Related
first try and bit stuck on this one...
I Have a ViewController that I wish to display an SKScene in its view
I've tried everything I can think of but its not showing
add SpriteKit/SpriteKit.h
Main.storyboard has a single view controller (myViewController).
myViewController's view - change class to be SKView. (see pic below)
Viewdidload
link to SKScene I wish to load (HelloScene) #import "HelloScene.h"
//ViewController.m
#import "myViewController.h"
#import <SpriteKit/SpriteKit.h>
#import "HelloScene.h"
#interface myViewController ()
#end
#implementation myViewController
- (void)viewDidLoad
{
[super viewDidLoad];
SKView *spriteView = (SKView *) self.view;
spriteView.showsDrawCount = YES;
spriteView.showsNodeCount = YES;
spriteView.showsFPS = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
HelloScene.h
#import <SpriteKit/SpriteKit.h>
#interface HelloScene : SKScene
#end
HelloScene.m
#import "HelloScene.h"
#interface HelloScene ()
#property BOOL contentCreated;
#end
#implementation HelloScene
- (void)didMoveToView: (SKView *) view
{
[self LoadSceneContents];
}
- (void)LoadSceneContents
{
self.backgroundColor = [SKColor blueColor];
self.scaleMode = SKSceneScaleModeAspectFit;
[self addChild: [self newHelloNode]];
}
- (SKLabelNode *)newHelloNode
{
SKLabelNode *helloNode = [SKLabelNode labelNodeWithFontNamed:#"Chalkduster"];
helloNode.text = #"Hello, World!";
helloNode.fontSize = 42;
helloNode.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
return helloNode;
}
#end
Above:Selecting the view controller’s view object and change its class to SKView
Had missed to configure the scene properly...
// Create and configure the scene.
HelloScene *theScene = [HelloScene sceneWithSize:spriteView.bounds.size];
theScene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[spriteView presentScene:theScene
];
Hope it helps somebody else
On iOS 8 I have a strange behavior regarding the navigation bar and orientation changes.
I have a navigation controller which reports a supported interface orientation UIInterfaceOrientationMaskLandscapeRight. The navigation bar has the expected height for landscape orientation (sadly I am not entitled to post screenshots).
Then I initiate a modal presentation of a view controller that only supports UIInterfaceOrientationMaskPortrait. When the presentation animation starts, it seems that the metrics of the underlying navigation controller are changed to a portrait presentation, as the height of the navigation bar grows to its portrait size, as depicted above.
iOS 7 does not exhibit this behavior. What am I missing? I want to restore the old behavior.
Here is the full code of the simple example above:
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
DOGButtonViewController *root = [DOGButtonViewController new];
DOGOrientedNavigationController *navi = [[DOGOrientedNavigationController alloc] initWithRootViewController:root];
navi.allowedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight;
self.window.rootViewController = navi;
[self.window makeKeyAndVisible];
return YES;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait;
}
#end
#implementation DOGOrientedNavigationController
- (NSUInteger)supportedInterfaceOrientations
{
return self.allowedInterfaceOrientations;
}
#end
#implementation DOGButtonViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Button View Controller";
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (IBAction)buttonClicked:(id)sender
{
DOGPortraitViewController *vc = [DOGPortraitViewController new];
[self presentViewController:vc animated:YES completion:nil];
}
#end
#implementation DOGPortraitViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Portrait Title";
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (IBAction)buttonClicked:(id)sender
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
#end
In a more complex setup I also experience the text in a UIWebView contained in the navigation controller being scaled up when presenting the portrait modal. When dismissing the modal, the text is not resized to its original size.
For lack of a better option I've done a bit of a hack for this.
Basically before I show the modal view I take a screen shot and lay it on top of the presenting view controller.
Obviously I have to remove this screen shot when the view re-appears
func showScreenShot () {
let image = screenShot()
self.screenShotImageView = UIImageView(image: image)
self.view.addSubview(self.screenShotImageView!)
}
func screenShot () -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, UIScreen.mainScreen().scale)
self.view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image
}
func removeScreenShot () {
if let screenImageView = self.screenShotImageView {
screenImageView.removeFromSuperview()
self.screenShotImageView = nil
}
}
My app has 3 view controllers. VC#3(*Sponsor) takes the user to my website & so I am trying to implement Reachability for this VC. I added System Configuration framework & Apples Reachability .H & .M files to the project. Disabled ARC for Reachability .M file & VC#3 .M file. The project B&R fine, but I still do not get the pop up alert when disconnected from internet. I imported Reachability.h to VC#3 also. What am I missing?
VC#3(*Sponsor).M
#import "Sponsor.h"
#import "ViewController.h"
#interface Sponsor ()
#end
#implementation Sponsor
-(void)viewDidLoad {
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:#"http://opticertificationprep.webs.com/"]]];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(IBAction)home:(id)sender{
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (BOOL) hasInternet {
Reachability *reach = [Reachability
reachabilityWithHostName:#"www.opticertificationprep.webs.com"];
NetworkStatus internetStats = [reach currentReachabilityStatus];
if (internetStats == NotReachable) {
UIAlertView *alertOne = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Check Your Internet Connection" delegate:self cancelButtonTitle:#"Okay"
otherButtonTitles:nil];
[alertOne show];
[alertOne release];
}
return YES;
}
For anyone with same problem. I was missing this bit of code in the the .M file. Once I added it my pop up alert works great.
`
-(void)viewDidLoad {
{
[super viewDidLoad];
[self hasInternet];
}
`
I'm trying to load google maps view in iOS following the guide here
I created a new viewController for the map view called iptechMapViewController.h , iptechMapViewController.m and iptechMapViewController.xib
Here is the code in iptechMapViewController.m :
#import "iptechMapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#interface iptechMapViewController ()
{
GMSMapView *mapView_;
}
#end
#implementation iptechMapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Then in another view controller named iptechFlipsideViewController.m I'm trying to show the iptechMapViewController as follows:
- (IBAction)showMap:(id)sender
{
iptechMapViewController *controller = [[iptechMapViewController alloc] initWithNibName:#"iptechMapViewController" bundle:nil];
[self.view addSubview:controller.view];
}
But after clicking the showMap button which is connected to the IBAction showMap, and after iOS asks permission to access my location alert appears and I touch OK, after that nothing shows up and in the console I get the following error"
Failed to make complete framebuffer object 8cd6
Thanks
Passing CGRectZero to mapWithFrame only works if the map view is the root view controller's root view - in which case it is resized to fit the screen. In your case since the map is a subview, you will need to specify a size when creating the map view.
here is my code:
#import "VirusViewController.h"
#import "MainGame.h"
#import "cocos2d.h"
#implementation VirusViewController
#synthesize window;
- (void)loadView {
// Initialization code
CC_DIRECTOR_INIT();
CCDirector *director = [CCDirector sharedDirector];
//landscape
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[director setDisplayFPS:YES];
//turn on multi-touch
EAGLView *cocosView = [director openGLView];
[cocosView setMultipleTouchEnabled:YES];
self.view = cocosView;
//default texture formats...
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene:[MainGame scene]];
}
-(void)viewDidLoad
{
UIButton *nextButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 40, 64, 64)];
[nextButton setImage:[UIImage imageNamed:#"homeButton.png"] forState:UIControlStateNormal];
[nextButton addTarget:self action:#selector(goBack) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nextButton];
[nextButton release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[[CCDirector sharedDirector] purgeCachedData];
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[[CCDirector sharedDirector] release];
[window release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
-(void)goBack
{
[self.navigationController popViewControllerAnimated:YES];
}
nextButton is not receiving touch events when i init the CC_Director_INIT();
also - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
is not working inside a subview of MainGame.h
in other words... I can't receive any touch events
Try giving your layer these methods
- (void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
[super onEnter];
}
- (void)onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
sharedDispatcher is deprecated - you should use this instead:
[[CCDirector sharedDirector] touchDispatcher]