Animation code stopped working - xcode

I have animation code in my AppDelegate file thats making the Default.png splashscreen to fade
out to the first controller of the app.
Since I implemented TabBar in my code, the animation stopped working.
Any idea why?
- (void) splashFade
{
splashView = [[UIImageView alloc]
initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[_window addSubview:splashView];
[_window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView
setAnimationTransition:UIViewAnimationTransitionNone
forView:_window cache:YES];
[UIView setAnimationDelegate:self];
[UIView
setAnimationDidStopSelector:
#selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
[UIView commitAnimations];
}
- (void)startupAnimationDone:(NSString *)animationID
finished:(NSNumber *)finished
context:(void *)context
{
[splashView removeFromSuperview];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(2);
[self splashFade];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
UIViewController *viewController2 = [[TableViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.rootViewController.view];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}

Try using
[self performSelector:#selector(splashFade) withObject:nil afterDelay:2];
better than sleep(2);

Related

ios 8 + xcode 6.01 + presentnavigationController + Screen does not rotate

Am presenting
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
LicenceAgreementViewController *licenceAgreementViewController = [[LicenceAgreementViewController alloc] initWithNibName:#"LicenceAgreementViewController" bundle:nil];
[self.navigationController presentViewController :licenceAgreementViewController animated:YES completion:nil];
[licenceAgreementViewController release];
And also did some changes in .plist itself
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskAll;
if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
// orientations = [presentedViewController supportedInterfaceOrientations];
}

No root view controller error on Xcode 5

I get this error on Xcode 5:
Application windows are expected to have a root view controller at the end of application launch
My code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[Flurry startSession:#"HJ4X7X6PB3942VGHQWWZ"];
screenRect = [[UIScreen mainScreen] applicationFrame];
if (screenRect.size.height > 500)
{
isFive = YES;
NSLog(#"is iPhone 5");
}else{
isFive = NO;
}
[[SQLiteOperator sharedOperator] openDatabase];
[self setupLang];
[self handleTabBarLanguage];
[self handleAppUpdatePopUpLanguage];
_banner_view_controller = [[BannerViewController alloc] initWithNibName:#"BannerViewController" bundle:nil];
[_banner_view_controller send_request];
[_banner_view_controller didHidden];
[_navigation_controller.view addSubview:_banner_view_controller.view];
[CoreData sharedCoreData].banner_view_controller = _banner_view_controller;
// Create content and menu controllers
//
DEMONavigationController *navigationController = [[DEMONavigationController alloc] initWithRootViewController:[[DEMOHomeViewController alloc] init]];
DEMOMenuViewController *menuController = [[DEMOMenuViewController alloc] initWithStyle:UITableViewStylePlain];
// Create frosted view controller
//
REFrostedViewController *frostedViewController = [[REFrostedViewController alloc] initWithContentViewController:navigationController menuViewController:menuController];
frostedViewController.direction = REFrostedViewControllerDirectionLeft;
frostedViewController.liveBlurBackgroundStyle = REFrostedViewControllerLiveBackgroundStyleLight;
// Make it a root controller
//
self.window.rootViewController = frostedViewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
If you are using storyboard click on the project name in project navigator in Xcode. Then look for deployment info. Select Main Interface as your storyboard name. In app delegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// // Override point for customization after application launch.
// self.window.backgroundColor = [UIColor whiteColor];
// [self.window makeKeyAndVisible];
return YES;
}
And now try it.

How should I reload tableview content after switching containers.

I have a container view that can be switched between a tableview and a mapview when a user presses a UIButton. det determines which container view it is currently in.
- (IBAction)changer:(id)sender{
if(det == TRUE){
TableViewController *viewController2 = [[TableViewController alloc]init];
viewController2.view.frame = self.container.bounds;
[viewController2 willMoveToParentViewController:self];
[self.container addSubview:viewController2.view];
[self addChildViewController:viewController2];
[viewController2 didMoveToParentViewController:self];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.container cache:YES];
[UIView commitAnimations];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 55, 35)];
[button setImage:[UIImage imageNamed:#"mapSwitch.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(changer:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setRightBarButtonItem:back];
det = FALSE;
}
else{
ViewController *viewController1 = [self.storyboard instantiateViewControllerWithIdentifier:#"vc1"];
viewController1.view.frame = self.container.bounds;
[viewController1 willMoveToParentViewController:self];
[self.container addSubview:viewController1.view];
[self addChildViewController:viewController1];
[viewController1 didMoveToParentViewController:self];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.container cache:YES];
[UIView commitAnimations];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 55, 35)];
[button setImage:[UIImage imageNamed:#"listSwitch.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(changer:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setRightBarButtonItem:back];
det = TRUE;
}
}
The switching is just fine; it loads the tableview first which is populated correctly. Then, if you switch to the mapview, it is also fine. However, when I switch back to the table view and call a
[self.tableView reloadData];
method, the tableview is empty. Basically I have 2 arrays of info that need to be displayed on the tableview which return the correct information/content after switching back to the tableview, but do not appear in the tableview after reloaddata.
Is reloadData is not the best way to reload a tableview that was created before? I suspect that when the changer method reloads the tableview container, something is happening so there is nothing in the table view.
Or is there a way to "cache" the tableview so when you switch back to it, everything stays rather than reloading everything again?

IOS allocation problems with MPMoviePlayerViewController

in my ipad app in viewDidLoad i set up a video in the first view so to have an intro.
In allocation tool i see that allocated memory grow till 120MB when running the video, ok i dont care, but after the video finish i would like that memory to go to 0 again BUT stick to 120MB, what am i doing wrong ?
- (void)viewDidLoad{
NSString *url = [[NSBundle mainBundle]
pathForResource:#"sfed"
ofType:#"mp4"];
playerViewController = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[videoview addSubview:playerViewController.view];
MPMoviePlayerController *player = [playerViewController moviePlayer];
player.view.frame = CGRectMake(1024, 748, 0, 0);
[player setControlStyle:MPMovieControlStyleNone];
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[player release];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1];
[videoview setAlpha:0];
[UIView commitAnimations];
[videoview release];
}

Deallocated NSMutableArray?

I can't work out what I am doing wrong with an NSMustableArray. It is fair to say that I don't really understand memory allocation that well, so I apologize if this is a simple questions.
I have a tab bar application that is working well, and on one of the tab bars I have a front view and a back view of a person.
In the .h I have
#interface BurnsCalculatorViewController : UIViewController// <UIPickerViewDelegate, UIPickerViewDataSource>
{
UIView *frontView;
UIView *backView;
UIButton *frontButton;
UIButton *backButton;
NSMutableArray *frontBurnsArray;
}
#property (nonatomic, retain) UIView *frontView;
#property (nonatomic, retain) UIView *backView;
#property (nonatomic, retain) UIButton *frontButton;
#property (nonatomic, retain) UIButton *backButton;
#property (nonatomic, retain) NSMutableArray *frontBurnsArray;
-(IBAction)frontButtonSelect:(id)sender;
-(IBAction)backButtonSelect:(id)sender;
#end
Then I have the .m file
#implementation BurnsCalculatorViewController
#synthesize frontView;
#synthesize backView;
#synthesize frontButton;
#synthesize backButton;
#synthesize frontBurnsArray;
-(IBAction)frontButtonSelect:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
[self.view addSubview:backView];
[self.view addSubview:backButton];
[UIView commitAnimations];
NSLog(#"%#", frontBurnsArray);
}
-(IBAction)backButtonSelect:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
[self.view addSubview:frontView];
[self.view addSubview:frontButton];
[UIView commitAnimations];
NSLog(#"%#", frontBurnsArray);
}
-(void)viewDidLoad
{
frontBurnsArray = [NSMutableArray arrayWithObjects: #"frontHead", #"frontChest", #"frontAbdomen", #"frontGroin",#"frontLeftArm", #"frontLeftForeArm", #"frontRightArm", #"frontRightForearm", #"frontLeftThigh", #"frontLeftLowerLeg", #"frontRightThigh", #"frontRightLowerLeg",nil];
CGRect viewframe = CGRectMake(0, 0, 320, 480);
frontView = [[UIView alloc] initWithFrame:viewframe];
frontView.backgroundColor = [UIColor blueColor];
[self.view addSubview:frontView];
frontButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[frontButton addTarget:self action:#selector(frontButtonSelect:) forControlEvents:UIControlEventTouchDown];
[frontButton setTitle:#"Show Back" forState:UIControlStateNormal];
frontButton.frame = CGRectMake(210, 10, 100, 30);
[self.view addSubview:frontButton];
backView = [[UIView alloc] initWithFrame:viewframe];
backView.backgroundColor = [UIColor blackColor];
backButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[backButton addTarget:self action:#selector(backButtonSelect:)forControlEvents:UIControlEventTouchDown];
[backButton setTitle:#"Show Front" forState:UIControlStateNormal];
backButton.frame = CGRectMake(210, 10, 100, 30);
}
-(void)dealloc
{
[super dealloc];
[frontButton release];
[backButton release];
[frontBurnsArray release];
}
#end
What I can't figure out is why the NSLogs in the IBActions are both telling me that the instance has been deallocated. Apart from the "release" in the dealloc, I am have said to retain the array and have not released it elsewhere.
I have spent ages searching for an answer to this, but just can't figure it out.
Thanks!!
frontBurnsArray = [NSMutableArray arrayWithObjects: #"frontHead", #"frontChest", #"frontAbdomen", #"frontGroin",#"frontLeftArm", #"frontLeftForeArm", #"frontRightArm", #"frontRightForearm", #"frontLeftThigh", #"frontLeftLowerLeg", #"frontRightThigh", #"frontRightLowerLeg",nil];
You are not using the retaining property
try
self.frontBurnsArray = [NSMutableArray arrayWithObjects: #"frontHead",
#"frontChest",
#"frontAbdomen",
//....
nil];
You are creating an array, that is autorealesed, meaning it will disappear on the next run-loop. If you assign it to the property, it get automatically retained and will exists until you release it. you also could call
frontBurnsArray = [[NSMutableArray arrayWithObjects: #"frontHead",
#"frontChest",
#"frontAbdomen",
//....
nil] retain];

Resources