MFSideMenu - center view doesn't resize - ios

I'm using MFSideMenu following the setup instructions, putting in didFinishLaunchingWithOptions this code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SideMenuViewController *leftMenuViewController = [[SideMenuViewController alloc] init];
SideMenuViewController *rightMenuViewController = [[SideMenuViewController alloc] init];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[self demoController]
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
I have tested this in demo project MFSideMenuDemoBasic, replacing [self navigationController] with [self demoViewController] simply because I don't want to use a navigation controller.
The problem is that the center view controller doesn't resize properly, it remains the same size also if running on iPad.
I'm having the same behaviour in my project and probably I'm missing something obvious.

add this to your demoController's viewDidLoad method (it worked for me):
self.view.frame = [[UIScreen mainScreen] bounds];
verify your view has autosizing set correctly...

Related

iOS - Setting first Screen after LaunchScreen

Im new to iOS development coming from an Android background and im looking to set the first screen after the launch screen.
I believe the relevant code is
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
The XIB file for the screen i want to set to first screen is called LoginView.xib
What do i need to do?
The boilerplate app im using is a mix of Swift and Objective C
Thanks
You also need to set the view controllers that should be handled by the tabbar controller. In your case, you need to instantiate the view controller that displays the view in LoginView.xib - I assume it is called LoginViewController:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [UITabBarController new];
LoginViewController *lvc = [[LoginViewController alloc] init];
// SecondViewController *secondVC = [[SecondViewController alloc] init];
// ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
rootViewController.viewControllers = #[lvc /*, secondVC, thirdVC */ ];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];
If you don't want a tab bar controller initally, then just use
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [LoginViewController new];
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self setup];

LeftSideMenu in MFSideMenu not responding

I'm implementing MFSideMenu in my project and this is my AppDelegate Code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[[UINavigationController alloc]
initWithRootViewController:[[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]]
leftMenuViewController:[[SideViewController alloc] initWithNibName:#"SideViewController" bundle:nil]
rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
}
The menu appear correctly and all of it's contents but the components inside it (button, tableview, etc...) not responding to any interaction . I've created a new clean project and add the menu only on it but with no hope.
Thanks in advance
you can try like this
SideViewController *leftMenuVC = [[SideViewController alloc] initWithNibName:#"SideViewController" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[[UINavigationController alloc]
initWithRootViewController:[[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]]
leftMenuViewController:[[UINavigationController alloc]initWithRootViewController:leftMenuVC] rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;

Overriding loadView and setting rootViewController programmatically, no Storyboard

I'm trying to create and set a View as the root View programmatically. I'm not using a Storyboard or ARC.
I'm trying to set a UIWebView as my ViewController's root View, which I'm unable to do. When I run the following code, I see a NavigationBar with a blank white screen. I tried setting a regular UIView as the root View and set its background color to blue, which loaded, so the problem seems to be specific to a UIWebView.
I'd really appreciate it if someone could point out what I'm doing wrong. Thanks!
Here is my loadView code:
// in GmailOAuthViewController.m
- (void)loadView {
CGRect frame = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[[UIWebView alloc] initWithFrame:frame] autorelease];
self.view = webView;
}
And here is my application:didFinishLaunchingWithOptions: code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect frame = [[UIScreen mainScreen] bounds];
UIViewController *viewController = [[GmailOAuthViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window = [[UIWindow alloc] initWithFrame:frame];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
you are assigning self.view...
if you assign webView to view everything else is gone
try
[self.view addSubview: webView]
this is code i just tried and it works
CGRect frame = [[UIScreen mainScreen] bounds];
UIViewController *viewController = [[ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window = [[UIWindow alloc] initWithFrame:frame];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
in ViewController.m
-(void)viewDidAppear:(BOOL)animated{
CGRect frame = self.view.bounds;
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame] ;
webView.delegate = self;
self.view = webView;
NSString *thePath = [[NSBundle mainBundle] pathForResource:#"ViewControllerCatalog" ofType:#"pdf"];
if (thePath) {
NSData *pdfData = [NSData dataWithContentsOfFile:thePath];
[(UIWebView *)self.view loadData:pdfData MIMEType:#"application/pdf"
textEncodingName:#"utf-8" baseURL:nil];
}
}
I apologize I told you wrong earlier you do in fact assign to view

UINavigationController not displaying

I am new to IOS dev so I'm sure the answer is simple but my ignorance makes it hard to find the answers online. I'm trying to use a UINavigationController to switch between views. Thus far I have been succesfully displaying the first view with the following code.
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
self.window.rootViewController = control;
I then wrote the code to add the navigation controller but when I run it I see mostly a black screen with a gray bar at the top of it. Here's the code
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
_navController = [[UINavigationController alloc] initWithRootViewController:control];
self.window.rootViewController = _navController;
Here is the complete code for AppDelegate.m in 'didFinishLaunchingWithOptions':
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FLInitialMapViewController *control = [[FLInitialMapViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController: control];
[self.navController setNavigationBarHidden:YES];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
Interestingly, the gray bar near the top is slightly translucent and I can see some of my UI elements underneath it.
EDIT: I removed the top bar and now I see the following!
This is what should be seen.
I have added navigation bar setup for your convenience. Try this in your AppDelegate.m under didFinishLaunchingWithOptions: method -
FLInitialMapViewController * control = [FLInitialMapViewController new];
UINavigationController *myNav = [[UINavigationController alloc] initWithRootViewController: control];
self.window.rootViewController = myNav;
// Setup navigation bar programmatically
UINavigationBar *navigationBar = myNav.navigationBar;
navigationBar.barTintColor = [UIColor orangeColor];
navigationBar.barStyle = UIBarStyleBlackOpaque;
// Boiler plate code from AppDelegate
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

Can't pop iOS viewController. Not sure, but I think it's something with the Navigation Controller

I'm having trouble trying to pop a view
App Delegate
#implementation MAAppDelegate
#synthesize navController;
#synthesize detailViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Init the navController for the Master Detail View of the grade cells
UINavigationController *navController = [[UINavigationController alloc] init];
detailViewController = [[UIViewController alloc] init]; //step6
navController = [[UINavigationController alloc] initWithRootViewController:[[MAController alloc] init]]; //step7
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = navController; //step8
[self.window makeKeyAndVisible];
// Set MAController as rootViewController
//self.window.rootViewController = [[MAController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// Use the insanely cool TSMessages to show network alerts
[TSMessage setDefaultViewController: self.window.rootViewController];
return YES;
}
First part of viewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:YES];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:#"Home" style:UIBarButtonItemStyleBordered target:self action:#selector(home:)];
self.navigationItem.leftBarButtonItem=newBackButton;
Later, when I change the viewController
NSLog(#"Opened progress report");
UIViewController *detailViewControl = [[UIViewController alloc] init];
// Set progress report as the view controller
[self.navigationController pushViewController:detailViewControl animated:YES];
UIImage *background = [UIImage imageNamed:#"bg"];
// Add static image bg
self.backgroundImageView = [[UIImageView alloc] initWithImage:background];
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.backgroundImageView];
// Add blurred layer to image when tableView goes in front of it
self.blurredImageView = [[UIImageView alloc] init];
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill;
self.blurredImageView.alpha = 0;
[self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil];
[self.view addSubview:self.blurredImageView];
[self.navigationController setNavigationBarHidden:NO];
So I don't understand why that when I do this, a selector from the button (that I know fires, because I get Righthtere in my log):
-(void)home:(UIBarButtonItem *)sender {
NSLog(#"Righthtere");
// Set progress report as the view controller
[self.navigationController popToViewController:self animated:YES];
}
It doesn't go back to the initial view controller.
You seem to be confusing popToViewController and popViewControllerAnimated. popViewControllerAnimated removes the current view from the stack and brings the new stack top the active view controller. popToViewController pops the stack until the listed view controller is on top of the stack.
Since you are calling popToViewController with self, it will look and see that the requested view controller is already on top of the stack and do nothing. If you wish to go back one view controller then your call should be.
[self.navigationController popViewControllerAnimated:YES];
I use the below code to pop the previous viewcontroller in iOS 8.
[self presentModalViewController:viewcontroller animated:YES];

Resources