calling a second view in iPad app - ios

I am trying to adapt an existing application to an iPad app. The application has a main view that calls View2 that is in "View2.xib". Everything has been working well, until I entered the following:
if(!view2Controller)
{
view2Controller = [[View2Controller alloc] initWithWindowNibName:#"View2"];
}
[view2Controller showWindow:self];
This works in my original Cocoa program, but in the iPad application it is currently returning a warning: "Thread1: Program received signal "SIGBRT" While working with it, I've also received a message Method -initWithWindowNibName not found.
Similarly, I have the same problem with the method showWindow.
I wonder how it is that this problem shows up when I try to convert it to an iPad app.
I've run out of ideas to check and would appreciate some assistance.

You will need to change it to the following
if(!view2Controller)
{
view2Controller = [[UIViewController alloc] initWithNibName:#"View2" bundle:nil]
}
//If you are in a view controller use
[self presentModalViewController:view2Controller animated:YES];

Related

Flurry ads integration using SDK 6.0 creates performance issue app crashes

Hi I am using latest flurry SDK 6.0 in app. I need to show ads almost every where in my app. App is UINavigationControllerBased contains more viewControllers. I am using code given in flurry documentation.
I am using below code in each and every ViewController but some times I move fast just like push and pop before add received,so in that case callbacks are continuously receiving but that viewcontroller is not available in stack at that time app crash or recieve memory. I tried to set adDelegate to nil in viewWillDisappear but flurry documentation says don't set it as nil.
Anyone has any ideas regarading this?
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if(self.adBanner == nil){
self.adBanner = [[FlurryAdBanner alloc] initWithSpace:#"Flurry Banner"] ;
self.adBanner.adDelegate = self;
[self.adBanner fetchAndDisplayAdInView:self.view viewControllerForPresentation:self];
}
}
Perhaps you should split the code in two?
Fetch the Ad using fetchAdForFrame. This prevents Flurry from using the view you passed.
Then inside the delegate, use displayAdInView. Only call this if you know the view is visible. So in viewWillAppear set a flag to say visible, in viewWillDisappear set a flag to say not visible. This should let you cut off the rendering part.
Seems odd an API like this would have no cancelFetchAd method!

How to call a view controller from AppDelegate in iOS

I am creating an iOS app in which I have the following requeriment: the app should show the login screen when it starts the first time and also that screen must also be shown when the app comes from the background to the foreground, in case it has been sent to background during run time.
I have handled to show the screen in both cases. However, when I do it and the app comes from the background, and I click the texfield to type my password, the app gets frozen, and it fails in a thread that I don't know what it means.
I call the screen to be shown when the app comes from background like this, in the applicationWillEnterForeground, in AppDelegate:
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RoomRootViewController* room = [[RoomRootViewController alloc] init];
[[self window] setRootViewController:room];
[self.window makeKeyAndVisible];
Is this the correct way to do so?
Thanks a lot in advance ! I am completely lost with this as I am very new in iOS, so any help will be very appreciated.
Attached in an image you can see where the app fails.
The code you are currently using is completely deleting the root view controller of your app window, in other words, you are deleting all the views and view controllers in your app. If you are not using ARC, this is just one huge memory leak. If you are, it's still not a very good idea.
In your applicationWillEnterForeground: method, try using this code instead:
RoomRootViewController* room = [[RoomRootViewController alloc] init];
[self.window.rootViewController presentViewController:room
animated:NO
completion:nil];
This will display the RoomRootViewController over the top of all your app's current views, instead of deleting them. You can then dismiss it like this:
[self.window.rootViewController dismissViewControllerAnimated:YES
completion:nil];
and easily return to the rest of your app.
It will be very messy if you are using this line of code
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
It means every time you are creating new instance of UIWindow which will contain UIViewController and all other component each time. Which means when you go to background and comes to foreground the old window instance has been flushed off and it will contain new components that's why when you click on the UITextField it has been deallocated, The reason you are getting error. Don't create new instance of window and use the code as #PartiallyFinite does.
Hope this helps.

MFMessageComposeViewController canSendText class returning YES on Simulator

Issue is pretty much in the title. Implementing the standard code everyone seems to use to send an SMS within an app and it's returning YES on the Simulator. Thought it could be because i'm using the iPhone Simulator but it does the exact same thing on the iPad Simulator. Not sure if sample code is worth posting, but here it goes..
.h
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
.m
-(void)sendSMS {
if([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = #"Hello";
controller.recipients = [NSArray arrayWithObjects:nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
It doesn't crash the Simulator, it shows a Modal VC with a standard blue Navigation Bar and just black content.
My main concern is that it will return YES on devices that cannot support it (ie. iPod/iPad). If it's a bug within the Simulator then i'll settle for that. Used this code plenty of times and it's always returned NO when running on the simulator. I havn't got access to an iOS device without SMS capabilities so i can't test it.
Any ideas? Is the problem staring me in the face? Thanks for any help.
This is a bug in the simulator, rest assured, in Xcode 4.3 it just pops up an empty view controller with the following console message:
Application tried to push a nil view controller on target <MFMessageComposeViewController: 0x805eb20>
But with Xcode 4.2, it crashes... not so good...

iOS 5: Twitter composer view appears slowly

I have a question about presenting the TWTweetComposerViewController as a modal view in iOS 5.
I use the apple sample code as below to implement a tweet method in my app.
-(void)tweet
{
//Using tweeting example code.
//Setup the build-in twitter composer view controller
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc]init];
//Add url
[tweetViewController addURL:[self URL]];
[tweetViewController setInitialText:#""];
//Present Composer
[self presentModalViewController:tweetViewController animated:YES];
//Creat the completion handler
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result)
{
//Do something here.
[self dismissModalViewControllerAnimated:YES];
}];
[tweetViewController release];
}
This works fine, when I call the tweet method, the tweet controller does appear as a modal view.
However, the problem is: the composer shows up very slowly. It usually takes 3-5 seconds to show the composer. Of course, this is when the app calls this method for the first time. After the first time, it shows up a little bit quicker, but still take about 1~2 seconds.
I wonder if is there something I didn't do right to make the composer view appear slowly? Is there any way to speed up the process?
Btw. the testing device is the iPhone 4.
Thanks!
Yes, there is. You can preload the class by initializing it in the background sometime before you'll ever need it. Move tweetViewController into an instance or static variable, initialize and set all of its properties. Then just show it in the tweet method.

iPad open a modalViewController at application launch

here is my problem: I have an iPad application based on a SplitViewController. When I launch the application, since it always starts in portrait mode, only the Detail pane is shown. All right. I want now open a modalViewController at the application launch for login purpose, but I am not able to find out the right way. I grasp on the web the following code:
SampleModalViewController *sampleView = [[[SampleModalViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
and it runs nicely, but where do I have to place it in order to have the modal controller displayed at startup? I tried to override viewDidLoad in the DetailViewController, but it does not work.
Thanks for your help!
Roberto
They suggested me an answer:
http://forums.macrumors.com/showthread.php?t=1097839

Resources