login window on another view controller iPhone - iphone

In Facebook API in FBDialoge.m file ,
I want that login window to open on another VC,
so in FBDialoge.m file ,
I am changing this code ..
UIWindow* window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[window addSubview:self];
[window addSubview:_modalBackgroundView];
to
SettingsPopover *svp = [[SettingsPopover alloc] init];
[svp.view addSubview:self];
[svp.view addSubview:_modalBackgroundView];
but that login window is not coming on SettingsPopover , can anyone tell me what should I do here?

Here instance of SettingsPopover *svp is new one which will add subviews but will not take effect until this new instance is used. Where ever u added SettingsPopover in viewcontroller that the reference i m talking about.
I mean u need original reference of SettingsPopover to take effect by adding subview.

Related

UIView not appearing over keyboard?

I have this code:
JMenuController *menuController = [[JMenuController alloc] init];
NSArray *buttonsArray = [NSArray arrayWithObjects:#"From Libary", #"Take Photo or Video", nil];
[menuController showMenuWithTitle:#"Add Media" ButtonTitles:buttonsArray animated:YES];
self.currentMenuType = JCreateMenuTypeNewMedia;
[[[[UIApplication sharedApplication] delegate] window] addSubview:menuController];
The problem is, the view appears below the keyboard, which is already on screen. How do i fix this?
The easiest way to display some view on top of the keyboard is put that view inside a UIWindow for which you set the windowLevel property to UIWindowLevelAlert. Something like:
UIView *myView = [[UIView alloc] initWithFrame:rect];
UIWindow *myWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
myWindow.windowLevel = UIWindowLevelAlert;
[myWindow addSubview:myView];
[myWindow makeKeyAndVisible];
If you're using ARC, make sure you keep a strong reference to myWindow. Otherwise, it'll get automatically released and so it won't get added to your application windows.
(This is how UIActionSheet and UIAlertView work internally. When one of them is visible, have a look at [UIApplication sharedApplication].windows and you'll see they create windows with their windowLevel set to UIWindowLevelAlert.)
Ok it took awhile for me to understand what you wanted to do. You have 2 options.
Resign the keyboard and show the view with the buttons.
Use a UIActionSheet to display the buttons over the keyboard like it does in the Messages application when you press the camera to send a picture to someone.
I would recommend the later.
Edit:
Take a look at this for your custom UIActionSheet Show a view over the keyboard
The keyboard exists in its own window. To put things over it, you either have to put things into the keyboard's window (this is not a supported behavior), or create yet another window and put it over the keyboard.

How to hide an image for few milliseconds while page is loading.

I have a common image on number of pages of my project, so I place that image on window file.
As some pages need not to display that image so i hide that image on corresponding pages.
Now problem arises, as i pop from non- image page to page containing image, that image displays before loading the whole page.
I want that image to appear only when whole page is loaded.
Any help is appreciated....
code of my firstViewController:
ProfileViewController *ProfilePage = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
ProfilePage.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *navigationControllerNew = [[UINavigationController alloc] initWithRootViewController:ProfilePage];
//Present navigationController as Model viw controller
[self.navigationController presentModalViewController:navigationControllerNew animated:YES];
//release it After presenting to it
[navigationControllerNew release];
[ProfilePage release];
on ProfileViewController page I am hiding image with following code:
[super viewWillAppear:animated];
IQ_TestAppDelegate *appDelegate = (IQ_TestAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate removeImageViewLogo];
this how I am calling my Pages....
EDIT: I have already used NSTimer, so that image is hidden for some milliseconds, but as i told I placed that image in window file, it displays at the beginning of the page loading, dont know wat to do....
Please help.
You should try and display (make visible) the image in the viewDidLoad method of your controller.
If you have a model that loads some data asynchronously, then you should make the image visible only at the end of this process.
If you provide more details, specifically what you mean by "whole page is loaded", I can help further.

Problem with getting a modalViewController to appear

I've been fighting with this for hours. I've searched around everywhere and just can't seem to find the solution to my problem. I'm pretty sure I'm just lacking some key concepts here.
My AppDelegate (didFinishLaunching) basically sets up my window and invokes RootViewController:
// create our window
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setBackgroundColor:[UIColor blackColor]];
// create our rootviewcontroller
RootViewController *controller = [[RootViewController alloc] init];
// add our rootviewcontroller's view to our window
[window addSubview:controller.view];
// controller is now owned by window's view
[controller release];
// show us to the world
[window makeKeyAndVisible];
When I add controller.view as window's subview, my understanding is that RootVC's loadView will automatically get called.
In RootVC loadView, I create a tabBarController, each tab having a navigationController and it's own viewController. All that is working fine.
In RootVC viewDidLoad, I'm checking to see if this is the first time a user is running this app, and if so, I want to throw up a modal welcome screen. This is the part I'm having trouble with.
I'd like to keep as much code out of the RootVC's viewDidLoad method, and ideally would be able to accomplish what I want with this:
WelcomeViewController *welcome = [[WelcomeViewController alloc] init];
[self presentModalViewController:welcome animated:true];
[welcome release];
Obviously this isn't working. WelcomeVC's loadView hasn't been run yet because I haven't explicitly set it's view property. I've played around with a bunch of different solutions (welcome.view - [[UIView....], using WelcomeVC's init method to set self.view) but I just can't seem to get that modal to pop up.
How should I accomplish what I'm looking for? What are the best practices, and what's the best solution to keep my code tight and tidy?
I'm stuck, so hopefully your solution will allow me to continue developing my app!
Although the problem is not so simple, the solution is. You have to wait until the main view appears. So check the condition and present your modal view in viewDidAppear method, not in viewDidLoad method.

How can I "reset" the tabbar in an iPhone application

I've an iPhone application:
When you open the app you see the "LoginView". If you login into application you see a TabBarController. In the third and last tab there is "Logout" button. If you click you see the "LoginView" again. My problem is that if you login again you see the "old" tabbar and the selected tab is the third and not the one, and there is a "Logout" button. Also, if a user login with a different user, see the old data of the previous user (very dangerous).
Here's the code:
- Delegate.h:
UITabBarController *tabBarController;
LoginViewController *loginView;
- Delegate.m (didFinishLaunchingWithOptions):
[self.window makeKeyAndVisible];
loginView = [[LoginViewController alloc] init];
if (YES) { /* if the user is not already logged */
[self.window addSubview:loginView.view];
}
Delegate.m (methods):
- (void)loginComplete {
[loginView dismissModalViewControllerAnimated:YES];
[window addSubview:tabBarController.view];
}
- (void)logoutComplete {
[[tabBarController view] removeFromSuperview];
[tabBarController release];
[window addSubview:loginView.view];
}
And here's the two methods in two different viewcontrollers:
- (IBAction)login:(id)sender {
TabNavisAppDelegate *delegate =
(TabNavisAppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate loginComplete];
}
(the logout method is the same)
Guys, how can I solve this painful problem?
So, here's a list of application that do what I want: "Foursquare", "Brightkite" and others.
Each one have a login screen, a tabbar view and a logout button.
Thanks # everyone.
For login-logout-login situations where all kinds of things need to reset themselves at the logout or the next login, I like to create a notification, something like "NewUserReset." Everything that needs to reset itself to an original state listens for the notification and runs a method that does whatever kind of resetting it needs. The tabbar would change the button title to logout, temporary data structures nil/zero/release themselves, etc.
It's nicely decouples the logout from all of the things that have to be done so you're not trying to manipulate view controllers and data storage and view appearances from the the controller that received the logout tap.
Sending a notification is easy. When the user taps the Logout button you'll send out a notification like this:
[[NSNotificationCenter defaultCenter] postNotificationName:#"JMUserLogout"
object:nil];
You don't have to call it JMUserLogout, you just need a string that you'll recognize and something -- I used your initials -- to help ensure you don't accidentally send a notification that has the same name as a notification something you're unaware of is listening for.
When that notification goes out, any object that has registered with the defaultCenter to listen for #"JMUserLogout" will perform any actions you choose. Here's how your object registers (this should be located in some place like ViewWillLoad or the initialization method of the object):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(resetForNewUser:)
name:#"JMUserLogout"
object:nil];
The selector there, resetForNewUser:, is just the name of a method you want to run when the notification goes out. That method looks like this:
- (void)resetForNewUser:(NSNotification *)notif {
// DO SOMETHING HERE
}
Where it says // DO SOMETHING HERE you'll add the code specific to your app. For example, you can add the tab bar as an observer of the JMUserLogout notification. In its resetForNewUser: method you'd change the name of the logout button to Login.
In a ViewController or View or data store that holds old data from the previous user the resetForNewUser method would delete all of that data and set things back to the way they should be fore a new user. For example, if the previous user entered data into a UITextField you would delete the text, yourTextFieldName.text = #"";
Lastly, it's important that you also remove your object as an observer before it's deallocated. In your Dealloc method of each object that registered to receive the notification you add this:
[[NSNotificationCenter defaultCenter] removeObserver:self];
Hopefully that makes sense. The Apple documentation for NSNotificationCenter explains more and they provide several sample apps that use notifications.
Seems like tabBarController is not getting released. [ retain count should be 1 before releasing] tabBarController might be retain somewhere. check the retain count of it.
If you want to reset the old data from the previous user after you log out.. all you have to do is reset the UITabBarController's viewControllers property.
So if you are subclassing UITabBarController the following code should restore your app to its original state.
self.viewControllers = #[self.viewControllerOne, self.viewControllerTwo, self.viewControllerThree];
From the documentation:
If you change the value of this property at runtime, the tab bar controller removes all of the old view controllers before installing the new ones. The tab bar items for the new view controllers are displayed immediately and are not animated into position.
The tabBarController object may have been retained somewhere. Try to remove that.
And use the following code for Login, Logout methods
- (void)loginComplete {
// initialize the tabBarController here. like the following
if(tabBarController == nil){
tabBarController = [[UITabBarController alloc] init];
}
[loginView dismissModalViewControllerAnimated:YES];
[window addSubview:tabBarController.view];
}
- (void)logoutComplete {
[[tabBarController view] removeFromSuperview];
[tabBarController release];
tabBarController = nil;
[window addSubview:loginView.view];
}
So that your problem will be solved.

How can I display a introduction modal view when the app start up?

I have a tab bar application and I want to display those views that most part of apps have, with the name of the company or the name of the app.
I've created the follow viewController
Introduction *introducao = [[Introduction alloc] initWithNibName:#"Introduction" bundle:nil];
I don't know where exactly should I insert the code to show the modal because I have a tab bar application:
[self.navigationController presentModalViewController:galeria animated:YES];
I've tried to insert these lines on appDelegate.. but didn't work.. somebody have an idea?
if you are trying to show a splash screen right when the application opens, you should use a Default.png image instead of a view controller showing an image. Check out the Apple Documentation on Human Interface Guidelines and Beginning iPhone Development.
First of all, you'll need to ensure that you have a navigation controller present to present the model view from. Otherwise in the above code you'll be messaging nil and nothing will happen. Then you'll want to put the presentModalViewController:animated: call in your app delegate's applicationDidFinishLaunching: implementation.
Thanks for all answers.. they were very useful to understand better the process..
I have found a solution that does exactly what I need! So if someone need to create those splash screens with a sequence of images it is very useful:
Just create a ImageView on the Delegates Header and do the following:
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
to control the duration of the splash screen:
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:1.5];
To remove the splash:
-(void)removeSplash;
{
[splashView removeFromSuperview];
[splashView release];
}
so If you want to create a sequence of image just create a method to change the splashView.image.. and create a NSTIMER to call it..