After pushing view controller getting blank page on objective c - objective-c

I'm trying to push a view controller from the appdelegate. Its redirecting to the proper view controller but the UI is missing.
Code
-(void)checkConditionToMoveToPaynoteDetailPage
{
if([_topViewController isKindOfClass:[TCSPayNoteHomeViewController class]])
{
[[NSNotificationCenter defaultCenter] postNotificationName:popCurrentPaynoteDetailPage object:self];
[self performSelector:#selector(moveToPaynoteDetailPage) withObject:nil afterDelay:2];
}
else{
BOOL ctrlIsPresent = NO;
for (id ctrlr in self.navigationCtrlArray ) //required controlled is in betwwen
{
if([ctrlr isKindOfClass:[TCSPayNoteHomeViewController class]])
{
ctrlIsPresent = YES;
}
}
if(ctrlIsPresent) //required controlled is in betwwen
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.navController popToViewController:[self.navigationCtrlArray objectAtIndex:0] animated:YES]; // top is required controller
[self performSelector:#selector(moveToPaynoteDetailPage) withObject:nil afterDelay:2];
});
}
else{
[self moveToPaynoteDetailPage];
// rquired controller is not in a stack
}
}
}
-(void)moveToPaynoteDetailPage
{
UIViewController *viewController = [self getTopViewController];
TCSPayNoteHomeViewController *paynoteDetailCtrl= [[TCSPayNoteHomeViewController alloc] init];
TCSPayNote *payNoteData = [[TCSPayNote alloc] init];
payNoteData.payNoteEntryID = [_notifInfo valueForKey:#"id"];
paynoteDetailCtrl.payNoteData = payNoteData;
[viewController.navigationController pushViewController:paynoteDetailCtrl animated:NO];
}
View controller
-(UIViewController*)getTopViewController
{
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
UIViewController *viewController = navController.topViewController;
return viewController;
}
-(void)getNavigationCtrlArray
{
self.navController = (UINavigationController *)self.window.rootViewController;
self.navigationCtrlArray = [self.navController viewControllers];
}
I'm trying to push a view controller from the appdelegate. Its redirecting to the proper page but UI's are not loading while pushing.

I do something similar somewhere but have a different function for getTopViewController. Here is my code.
// Find and return top view controller
+ ( UIViewController * ) topViewController
{
return [fmUiUtil topViewControllerFrom:UIApplication.sharedApplication.keyWindow.rootViewController];
}
// Given a starting point, find the best top view controller
+ ( UIViewController * ) topViewControllerFrom:( UIViewController * ) vc
{
if ( vc.presentedViewController )
{
return [fmUiUtil topViewControllerFrom:vc.presentedViewController];
}
else if ( [vc isKindOfClass:UISplitViewController.class] )
{
UISplitViewController * svc = ( UISplitViewController * ) vc;
if ( svc.viewControllers.count )
{
return [fmUiUtil topViewControllerFrom:svc.viewControllers.lastObject];
}
else
{
return vc;
}
}
else if ( [vc isKindOfClass:UINavigationController.class] )
{
UINavigationController * svc = ( UINavigationController * ) vc;
if ( svc.viewControllers.count )
{
return [fmUiUtil topViewControllerFrom:svc.topViewController];
}
else
{
return vc;
}
}
else if ( [vc isKindOfClass:UITabBarController.class] )
{
UITabBarController * svc = ( UITabBarController * ) vc;
if ( svc.viewControllers.count )
{
return [fmUiUtil topViewControllerFrom:svc.selectedViewController];
}
else
{
return vc;
}
}
else
{
return vc;
}
}
Also, in the delegate, I use [topVC presentViewController ... and not [topVC.navigationController pushVC as you do.

Related

self.splitViewController.navigationController pushViewController can't work

UIsplitViewController can't pushViewController, only the master view or only detail view can pushViewController inside it's view. I wan't to push a new view int the current UIsplitViewController. The UIsplitViewController is in a UITabBarController.
How to solve it?
self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
[MLTool pushView:self newView:USER_VIEW];
+(id)pushView:(UIViewController*)view newView:(NSString*)newView{
UIViewController *svc = [view.storyboard instantiateViewControllerWithIdentifier:newView];
//NSAssert(svc, #"pushView nil");
[view.navigationController pushViewController:svc animated:YES];
return svc;
}
- (void)viewWillAppear:(BOOL)animated{
SplitProductView* split=(SplitProductView* )self.splitViewController;
[split resetSplit: [[UIApplication sharedApplication] statusBarOrientation]];
//self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay
}
-(void)resetSplit :(UIInterfaceOrientation)toInterfaceOrientation {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
//TODOX:iphone
if (isPad)
{
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
}
else{
//if (self.displayMode == UISplitViewControllerDisplayModePrimaryOverlay)
{//ios的bug,必须这三行,不然左边有黑边
// if (SYSTEM_VERSION_MORE_THAN(#"8.0"))
{
self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
self.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic;
}
}
}
}
}
}

How To Hide Tab Bar in Navigation Interface in React Native?

In Native IOS, seems it's very easy to hide the tab bar in Navigation interface (http://www.appcoda.com/ios-programming-101-how-to-hide-tab-bar-navigation-controller/), but in React Native, seems it's not so easier to implement that. Even I override the hidesBottomBarWhenPushed method for RCTWrapperViewController:
- (BOOL) hidesBottomBarWhenPushed
{
return YES;
}
This is a more in depth answer based on this issue in React-Native
In Xcode's lefthand sidebar, choose the 'Project Manger' (folder icon) to see the file structure.
The particular folder you are looking for is found at:
[YourAppName] > Libraries > React.xcodeproj > React > Views
RCTNavItem.h
#import "RCTComponent.h"
#interface RCTNavItem : UIView
//add this line:
#property (nonatomic, assign) BOOL showTabBar;
RCTNavItemManager.m
#implementation RCTNavItemManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
return [RCTNavItem new];
}
// add this line:
RCT_EXPORT_VIEW_PROPERTY(showTabBar, BOOL)
RCTNavigator.m
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(__unused UIViewController *)viewController
animated:(__unused BOOL)animated
{
// Add these two lines:
RCTWrapperViewController *thisController = (RCTWrapperViewController *)viewController;
navigationController.tabBarController.tabBar.hidden = !thisController.navItem.showTabBar;
I did not need to add propTypes to NavigatorIOS.ios.js or TabBarIOS.ios.js
In order for this all to work, each tab seemingly needs to have its own NavigatorIOS component. When I had the tab simply present a screen the - (void)navigationController:(UINavigationController *)navigationController... method does not get called. This was not an issue for me, because hiding the navBar is easily done with navigationBarHidden: true.
In my case I had a TabNav > HomeNav > HomeScreen
Passing showTabBar prop in HomeNav:
render() {
return (
<NavigatorIOS
style={styles.container}
client={this.props.client}
initialRoute={{
title: 'Home',
component: HomeScreen,
navigationBarHidden: true,
showTabBar: false,
passProps: { ...},
}}/>
);
}
}
I hope this helps someone!
You can try using the package below, it has a good solution for this
react-native-tabbar-navigator
In case that you are using the react-navigation package, it is quite simple:
class ScreenWhereTabbarIsHidden extends React.Component {
static navigationOptions = {
tabBarVisible: false,
}
}
I change ReactNative 0.11 source code for this problem.In case you need it:
In RCTNavigationController,add codes:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
if (self.viewControllers.count >= 1) {
[self hideTabBarIfExist:YES];
}
[super pushViewController:viewController animated:animated];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
if (self.viewControllers.count <= 2) {
[self hideTabBarIfExist:NO];
}
return [super popViewControllerAnimated:animated];
}
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ([self.viewControllers indexOfObject:viewController] == 0) {
[self hideTabBarIfExist:NO];
}
return [super popToViewController:viewController animated:animated];
}
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated{
[self hideTabBarIfExist:NO];
return [super popToRootViewControllerAnimated:animated];
}
- (void)hideTabBarIfExist:(BOOL)flag {
UIWindow *keyWindow = [[[UIApplication sharedApplication]delegate]window];
UIView *tabView = [self getTabBarView:keyWindow];
if (tabView) {
// you can use other animations
[UIView animateWithDuration:0.3 animations:^{
tabView.hidden = flag;
}];
}
}
- (UIView *)getTabBarView:(UIView *)pView {
if (pView == nil) {
return nil;
}
for (UIView *sView in [pView subviews]) {
if ([sView isKindOfClass:[UITabBar class]]) {
return sView;
}
UIView *t = [self getTabBarView:sView];
if (t) {
return t;
}
}
return nil;
}
RCTWrapperViewController.m
- (BOOL)hidesBottomBarWhenPushed
{
return self.navigationController.viewControllers.count != 1;
}
RCTTabBar.m
- (void)reactBridgeDidFinishTransaction
{
...
if (_tabsChanged) {
NSMutableArray<UIViewController *> *viewControllers = [NSMutableArray array];
for (RCTTabBarItem *tab in [self reactSubviews]) {
UIViewController *controller = tab.reactViewController;
if (!controller) {
NSArray *tabSubViews = [[[tab reactSubviews] firstObject] reactSubviews];
RCTNavigator *navigator = [tabSubViews firstObject];
if (!tabSubViews.count) {
tab.onPress(nil);
return;
}
else if ([navigator isKindOfClass:[RCTNavigator class]]) {
controller = navigator.reactViewController;
}
else {
controller = [[RCTWrapperViewController alloc] initWithContentView:tab];
}
}
[viewControllers addObject:controller];
}
_tabController.viewControllers = viewControllers;
_tabsChanged = NO;
RCTTabBarItem *tab = (RCTTabBarItem *)[[self reactSubviews] firstObject];
tab.onPress(nil);
}
...
}

Check to see if UIViewController has already been created

I'm trying to check if a viewcontroller has already been created. If the view already exists then it should become the current view. If it doesn't exist then it should be created and made visible.
My code is
DemoViewController *demoController = [DemoViewController alloc];
for(DemoViewController *view in self.navigationController.viewControllers)
{
if([view isKindOfClass:[DemoViewController class]])
{
viewExists=true;
demoController=view;
}
}
if (!viewExists) {
demoController initWithNibName:#"DemoViewController" bundle:nil;
}
[view release];
[demoController release];
I'm not sure where I'm going wrong but it would appear that the for loop isn't being executed.
Any help would be great!
Try like this:
DemoViewController* demoController = nil;
for(int vv=0; vv<[self.navigationController.viewControllers count]; ++vv) {
NSObject *vc = [self.navigationController.viewControllers objectAtIndex:vv];
if([vc isKindOfClass:[DemoViewController class]]) {
demoController = (DemoViewController*)vc;
}
}
if (demoController == nil) {
demoController = [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
// Do we need to push it into navigation controller?
}
[demoController release];

Singleton method not getting called in Cocos2d

I am calling a Singleton method that does not get called when I try doing this.
I get no errors or anything, just that I am unable to see the CCLOG message.
Under what reasons would a compiler not give you error and not allow you to call a method?
[[GameManager sharedGameManager] openSiteWithLinkType:kLinkTypeDeveloperSite];
The method is defined as follows:
-(void)openSiteWithLinkType:(LinkTypes)linkTypeToOpen
{
CCLOG(#"WE ARE IN openSiteWithLinkType"); //I NEVER SEE THIS MESSAGE
NSURL *urlToOpen = nil;
if (linkTypeToOpen == kLinkTypeDeveloperSite)
{
urlToOpen = [NSURL URLWithString:#"http://somesite.com"];
}
if (![[UIApplication sharedApplication]openURL:urlToOpen])
{
CCLOG(#"%#%#",#"Failed to open url:",[urlToOpen description]);
[self runSceneWithID:kMainMenuScene];
}
}
HERE IS THE CODE TO MY SINGLETON:
#import "GameManager.h"
#import "MainMenuScene.h"
#implementation GameManager
static GameManager* _sharedGameManager = nil;
#synthesize isMusicON;
#synthesize isSoundEffectsON;
#synthesize hasPlayerDied;
+(GameManager*) sharedGameManager
{
#synchronized([GameManager class])
{
if (!_sharedGameManager)
{
[[self alloc] init];
return _sharedGameManager;
}
return nil;
}
}
+(id)alloc
{
#synchronized ([GameManager class])
{
NSAssert(_sharedGameManager == nil,#"Attempted to allocate a second instance of the Game Manager singleton");
_sharedGameManager = [super alloc];
return _sharedGameManager;
}
return nil;
}
-(id)init
{
self = [super init];
if (self != nil)
{
//Game Manager initialized
CCLOG(#"Game Manager Singleton, init");
isMusicON = YES;
isSoundEffectsON = YES;
hasPlayerDied = NO;
currentScene = kNoSceneUninitialized;
}
return self;
}
-(void) runSceneWithID:(SceneTypes)sceneID
{
SceneTypes oldScene = currentScene;
currentScene = sceneID;
id sceneToRun = nil;
switch (sceneID)
{
case kMainMenuScene:
sceneToRun = [MainMenuScene node];
break;
default:
CCLOG(#"Unknown Scene ID, cannot switch scenes");
return;
break;
}
if (sceneToRun == nil)
{
//Revert back, since no new scene was found
currentScene = oldScene;
return;
}
//Menu Scenes have a value of < 100
if (sceneID < 100)
{
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
{
CGSize screenSize = [CCDirector sharedDirector].winSizeInPixels;
if (screenSize.width == 960.0f)
{
//iPhone 4 retina
[sceneToRun setScaleX:0.9375f];
[sceneToRun setScaleY:0.8333f];
CCLOG(#"GM: Scaling for iPhone 4 (retina)");
}
else
{
[sceneToRun setScaleX:0.4688f];
[sceneToRun setScaleY:0.4166f];
CCLOG(#"GM: Scaling for iPhone 3G or older (non-retina)");
}
}
}
if ([[CCDirector sharedDirector] runningScene] == nil)
{
[[CCDirector sharedDirector] runWithScene:sceneToRun];
}
else
{
[[CCDirector sharedDirector] replaceScene:sceneToRun];
}
}
-(void)openSiteWithLinkType:(LinkTypes)linkTypeToOpen
{
CCLOG(#"WE ARE IN openSiteWithLinkType");
NSURL *urlToOpen = nil;
if (linkTypeToOpen == kLinkTypeDeveloperSite)
{
urlToOpen = [NSURL URLWithString:#"http://somesite.com"];
}
if (![[UIApplication sharedApplication]openURL:urlToOpen])
{
CCLOG(#"%#%#",#"Failed to open url:",[urlToOpen description]);
[self runSceneWithID:kMainMenuScene];
}
}
-(void) test
{
CCLOG(#"this is test");
}
#end
Perhaps sharedGameManager is returning nil? This won't cause an error.
Edit: The issue is in the new code you posted:
if (!_sharedGameManager) {
[[self alloc] init];
return _sharedGameManager;
}
return nil;
If _sharedGameManager is non-nil, this will return nil. You want:
if (!_sharedGameManager) {
[[self alloc] init];
}
return _sharedGameManager;
Check this Cocoa With Love article on how to make a proper singleton.

Navigating to another view iPhone sdk?

I want to navigate to another view. I have like a now playing button for my radio application. I would like the view to mentain its state... the view that I want to navigate to has a text field for url of the radion and a label for radio name. so how can I mentain the state of that view because right now when ever I try to navigate it navigates fine but the text field changes.. so what can I do to not change the text?
here is some code sorry about wierd names
if (self.bookDetailViewController_1 == nil)
{
iPhoneStreamingPlayerViewController *aBookDetail = [[iPhoneStreamingPlayerViewController alloc] initWithNibName:#"iPhoneStreamingPlayerView" bundle:nil];
self.bookDetailViewController_1= aBookDetail;
[aBookDetail release];
}
Music_appAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.booksNavController pushViewController:bookDetailViewController_1 animated:YES];
Singleton implementation
//.h
+ (className *)sharedInstance;
//.m
static className* sharedInstance = nil;
#implementation className
+ (className*)sharedInstance {
if (!sharedInstance) {
sharedInstance = [[super allocWithZone:NULL] init];
}
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
return [[self sharedInstance] retain];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (id)retain {
return self;
}
- (NSUInteger)retainCount {
return NSUIntegerMax;
}
- (void)release { }
- (id)autorelease {
return self;
}
#end