Search Results

Search found 133 results on 6 pages for 'uiwindow'.

Page 3/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • UITabBarController rotation problem with popViewControllerAnimated and selectedIndex (iPhone SDK)

    - by rjobidon
    Hi! This is a very important auto rotate issue and easy to reproduce. My application has a UITabBarController. Each tab is a UINavigationController. Auto rotation is handled with normal calls to shouldAutorotateToInterfaceOrientation and didRotateFromInterfaceOrientation. The interface rotates normally until I call UIViewController.popViewControllerAnimated and change UITabBarController.selectedIndex. Steps to reproduce: Create a demo Tab Bar Application. Add the following code to the App Delegate .h file: #import <UIKit/UIKit.h> @interface TestRotationAppDelegate : NSObject { UIWindow *window; UITabBarController *tabBarController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; -(void)doAction; @end // Redefine the interface to cach rotation messages @interface UITabBarController (TestRotation1AppDelegate) @end Add the following code to the App Delegate .m file: #import "TestRotationAppDelegate.h" @implementation TestRotationAppDelegate @synthesize window; @synthesize tabBarController; -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [window addSubview:tabBarController.view]; [window makeKeyAndVisible]; return YES; } -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } -(void)dealloc { [tabBarController release]; [window release]; [super dealloc]; } @end @implementation UITabBarController (TestRotation1AppDelegate) -(void)viewDidLoad { [super viewDidLoad]; // Add a third tab and push a view UIViewController *view1 = [[UIViewController alloc] init]; view1.title = @"Third"; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view1]; NSMutableArray *array = [[NSMutableArray alloc] init]; [array addObjectsFromArray:self.viewControllers]; [array addObject:nav]; self.viewControllers = array; // Push view2 inside the third tab UIViewController *view2 = [[UIViewController alloc] init]; [nav pushViewController:view2 animated:YES]; // Create a button to pop view2 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(50, 50, 220, 38); [button setTitle:@"Pop this view" forState:UIControlStateNormal]; [button addTarget:self action:@selector(doAction) forControlEvents:UIControlEventTouchUpInside]; [view2.view addSubview:button]; } -(void) doAction { // ROTATION PROBLEM BEGINS HERE // Remove one line of code and the problem doesn't occur. [self.selectedViewController popViewControllerAnimated:YES]; self.selectedIndex = 0; } -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } @end The interface auto rotates normally until you tap the button on tab #3. Your help will be geatly appreciated!

    Read the article

  • copied the reachability-test from apple, but the linker gives a failure

    - by nico
    i have tried to use the reachability-project published by apple to detect a reachability in an own example. i copied the most initialization, but i get this failure in the linker: Ld build/switchViews.build/Debug-iphoneos/test.build/Objects-normal/armv6/test normal armv6 cd /Users/uid04100/Documents/TEST setenv IPHONEOS_DEPLOYMENT_TARGET 3.1.3 setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk -L/Users/uid04100/Documents/TEST/build/Debug-iphoneos -F/Users/uid04100/Documents/TEST/build/Debug-iphoneos -filelist /Users/uid04100/Documents/TEST/build/switchViews.build/Debug-iphoneos/test.build/Objects-normal/armv6/test.LinkFileList -dead_strip -miphoneos-version-min=3.1.3 -framework Foundation -framework UIKit -framework CoreGraphics -o /Users/uid04100/Documents/TEST/build/switchViews.build/Debug-iphoneos/test.build/Objects-normal/armv6/test Undefined symbols: "_SCNetworkReachabilitySetCallback", referenced from: -[Reachability startNotifer] in Reachability.o "_SCNetworkReachabilityCreateWithAddress", referenced from: +[Reachability reachabilityWithAddress:] in Reachability.o "_SCNetworkReachabilityScheduleWithRunLoop", referenced from: -[Reachability startNotifer] in Reachability.o "_SCNetworkReachabilityGetFlags", referenced from: -[Reachability connectionRequired] in Reachability.o -[Reachability currentReachabilityStatus] in Reachability.o "_SCNetworkReachabilityUnscheduleFromRunLoop", referenced from: -[Reachability stopNotifer] in Reachability.o "_SCNetworkReachabilityCreateWithName", referenced from: +[Reachability reachabilityWithHostName:] in Reachability.o ld: symbol(s) not found collect2: ld returned 1 exit status my delegate.h: import @class Reachability; @interface testAppDelegate : NSObject { UIWindow *window; UINavigationController *navigationController; Reachability* hostReach; Reachability* internetReach; Reachability* wifiReach; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @end my delegate.m: import "testAppDelegate.h" import "SecondViewController.h" import "Reachability.h" @implementation testAppDelegate @synthesize window; @synthesize navigationController; (void) updateInterfaceWithReachability: (Reachability*) curReach { if(curReach == hostReach) { BOOL connectionRequired= [curReach connectionRequired]; if(connectionRequired) { //in these brackets schould be some code with sense, if i´m getting it to run } else { } } if(curReach == internetReach) { } if(curReach == wifiReach) { } } //Called by Reachability whenever status changes. - (void) reachabilityChanged: (NSNotification* )note { Reachability* curReach = [note object]; NSParameterAssert([curReach isKindOfClass: [Reachability class]]); [self updateInterfaceWithReachability: curReach]; } (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch // Observe the kNetworkReachabilityChangedNotification. When that notification is posted, the // method "reachabilityChanged" will be called. // [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil]; //Change the host name here to change the server your monitoring hostReach = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain]; [hostReach startNotifer]; [self updateInterfaceWithReachability: hostReach]; internetReach = [[Reachability reachabilityForInternetConnection] retain]; [internetReach startNotifer]; [self updateInterfaceWithReachability: internetReach]; wifiReach = [[Reachability reachabilityForLocalWiFi] retain]; [wifiReach startNotifer]; [self updateInterfaceWithReachability:wifiReach]; [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; } (void)dealloc { [navigationController release]; [window release]; [super dealloc]; } @end

    Read the article

  • Showing login view controller before main tab bar controller

    - by Padawan
    I'm creating an iPad app with a tab bar controller that requires login. So on launch, I want to show a LoginViewController and if login is successful, then show the tab bar controller. This is how I implemented an initial test version (left out some typical header stuff, etc)... AppDelegate.h: @interface AppDelegate_Pad : NSObject <UIApplicationDelegate, LoginViewControllerDelegate> { UIWindow *window; UITabBarController *tabBarController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; @end AppDelegate.m: @implementation AppDelegate_Pad @synthesize window; @synthesize tabBarController; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { LoginViewController_Pad *lvc = [[LoginViewController_Pad alloc] initWithNibName:@"LoginViewController_Pad" bundle:nil]; lvc.delegate = self; [window addSubview:lvc.view]; //[lvc release]; [window makeKeyAndVisible]; return YES; } - (void)loginViewControllerDidFinish:(LoginViewController_Pad *)loginViewController { [window addSubview:tabBarController.view]; } - (void)dealloc {...} @end LoginViewController_Pad.h: @protocol LoginViewControllerDelegate; @interface LoginViewController_Pad : UIViewController { id<LoginViewControllerDelegate> delegate; } @property (nonatomic, assign) id <LoginViewControllerDelegate> delegate; - (IBAction)buttonPressed; @end @protocol LoginViewControllerDelegate -(void)loginViewControllerDidFinish:(LoginViewController_Pad *)loginViewController; @end LoginViewController_Pad.m: @implementation LoginViewController_Pad @synthesize delegate; ... - (IBAction)buttonPressed { [self.view removeFromSuperview]; [self.delegate loginViewControllerDidFinish:self]; } ... @end So the app delegate adds the login view controller's view on launch and waits for login to call "did finish" using a delegate. The login view controller calls removeFromSuperView before it calls didFinish. The app delegate then calls addSubView on the tab bar controller's view. If you made it up to this point, thanks, and I have three questions: MAIN QUESTION: Is this the right way to show a view controller before the app's main tab bar controller is displayed? Even though it seems to work, is it a proper way to do it? If I comment out the "lvc release" in the app delegate then the app crashes with EXC_BAD_ACCESS when the button on the login view controller is pressed. Why? With the "lvc release" commented out everything seems to work but on the debugger console it writes this message when the app delegate calls addSubView for the tab bar controller: Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. What does that mean and do I need to worry about it?

    Read the article

  • TabBarController rotation problem with popViewControllerAnimated and selectedIndex

    - by rjobidon
    Hi! This is a very important auto rotate issue and easy to reproduce. My application has a UITabBarController. Each tab is a UINavigationController. Auto rotation is handled with normal calls to shouldAutorotateToInterfaceOrientation and didRotateFromInterfaceOrientation. The interface rotates normally until I call UIViewController.popViewControllerAnimated and change UITabBarController.selectedIndex. Steps to reproduce: Create a demo Tab Bar Application. Add the following code to the App Delegate .h file: #import <UIKit/UIKit.h> @interface TestRotation2AppDelegate : NSObject { UIWindow *window; UITabBarController *tabBarController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; (void)doAction; @end // Redefine the interface to cach rotation messages @interface UITabBarController (TestRotation1AppDelegate) @end Add the following code to the App Delegate .m file: #import "TestRotation2AppDelegate.h" @implementation TestRotation2AppDelegate @synthesize window; @synthesize tabBarController; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [window addSubview:tabBarController.view]; [window makeKeyAndVisible]; return YES; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)dealloc { [tabBarController release]; [window release]; [super dealloc]; } @end @implementation UITabBarController (TestRotation1AppDelegate) - (void)viewDidLoad { [super viewDidLoad]; // Add a third tab and push a view UIViewController *view1 = [[UIViewController alloc] init]; view1.title = @"Third"; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view1]; NSMutableArray *array = [[NSMutableArray alloc] init]; [array addObjectsFromArray:self.viewControllers]; [array addObject:nav]; self.viewControllers = array; // Push view2 inside the third tab UIViewController *view2 = [[UIViewController alloc] init]; [nav pushViewController:view2 animated:YES]; // Create a button to pop view2 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(50, 50, 220, 38); [button setTitle:@"Pop this view" forState:UIControlStateNormal]; [button addTarget:self action:@selector(doAction) forControlEvents:UIControlEventTouchUpInside]; [view2.view addSubview:button]; } - (void) doAction { // ROTATION PROBLEM BEGINS HERE // Remove one line of code and the problem doesn't occur. [self.selectedViewController popViewControllerAnimated:YES]; self.selectedIndex = 0; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } @end The interface auto rotates normally until you tap the button on tab #3. Your help will be geatly appreciated!

    Read the article

  • 'object' undeclared <first use in this function>

    - by Mohit Deshpande
    I am using Winchain to develop on my Windows 7 machine. Here is my code: iPhoneTest.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface iPhoneTest : UIApplication { UITextView *textview; UIView *mainView; } @end iPhoneTest.m #import "iPhoneTest.h" #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <CoreFoundation/CoreFoundation.h> @implementation iPhoneTest -(void)applicationDidFinishLaunching:(id)unused { UIWindow *window; struct CGRect rect = [UIHardware fullScreenApplicationContentRect]; rect.origin.x = rect.origin.y = 0.0f; window = [[UIWindow alloc] initWithContentRect: rect]; mainView = [[UIView alloc] initWithFrame: rect]; textView = [[UITextView alloc] init]; [textView setEditable:YES]; [textView setTextSize:14]; [window orderFront: self]; [window makeKey: self]; [window _setHidden: NO]; [window setContentView: mainView]; [mainView addSubview:textView]; [textView setText:@"Hello World"]; } @end main.m #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "iPhoneTest.h" int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int ret = UIApplicationMain(argc, argv, [iPhoneTest class]); [pool release]; return ret; } Makefile INFOPLIST_FILE=Info.plist SOURCES=\ main.m \ iPhoneTest.m CC=/usr/local/bin/arm-apple-darwin-gcc CFLAGS=-g -O2 -Wall LD=$(CC) LDFLAGS=-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit PRODUCT_NAME=iPhoneTest SRCROOT=/iphone-apps/iPhoneTest WRAPPER_NAME=$(PRODUCT_NAME).app EXECUTABLE_NAME=$(PRODUCT_NAME) SOURCES_ABS=$(addprefix $(SRCROOT)/,$(SOURCES)) INFOPLIST_ABS=$(addprefix $(SRCROOT)/,$(INFOPLIST_FILE)) OBJECTS=\ $(patsubst %.c,%.o,$(filter %.c,$(SOURCES))) \ $(patsubst %.cc,%.o,$(filter %.cc,$(SOURCES))) \ $(patsubst %.cpp,%.o,$(filter %.cpp,$(SOURCES))) \ $(patsubst %.m,%.o,$(filter %.m,$(SOURCES))) \ $(patsubst %.mm,%.o,$(filter %.mm,$(SOURCES))) OBJECTS_ABS=$(addprefix $(CONFIGURATION_TEMP_DIR)/,$(OBJECTS)) APP_ABS=$(BUILT_PRODUCTS_DIR)/$(WRAPPER_NAME) PRODUCT_ABS=$(APP_ABS)/$(EXECUTABLE_NAME) all: $(PRODUCT_ABS) $(PRODUCT_ABS): $(APP_ABS) $(OBJECTS_ABS) $(LD) $(LDFLAGS) -o $(PRODUCT_ABS) $(OBJECTS_ABS) $(APP_ABS): $(INFOPLIST_ABS) mkdir -p $(APP_ABS) cp $(INFOPLIST_ABS) $(APP_ABS)/ $(CONFIGURATION_TEMP_DIR)/%.o: $(SRCROOT)/%.m mkdir -p $(dir $@) $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ clean: echo rm -f $(OBJECTS_ABS) echo rm -rf $(APP_ABS) When I try to compile it with make, I get iPhoneTest.m: In fucntion '-[iPhoneTest applicationDidFinishLaunching:]' iPhoneTest.m:15: error: 'testView' undeclared <first use in this function> iPhoneTest.m:15: error: <Each undeclared identifier is reported only once for each function it appears in> Can anyone spot the problem?

    Read the article

  • UIViewController rotate methods

    - by Corey Floyd
    What object is responsible for dipatching the UIViewController rotation method calls, i.e: – shouldAutorotateToInterfaceOrientation: – willRotateToInterfaceOrientation:duration: – willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: – willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration: – didRotateFromInterfaceOrientation: I imagine it is UIApplication (but maybe the AppDelegate or UIWindow). The next question, is how does the object know which UIViewController to talk to? How does it know which UIViewController has its view as the subview of the window? Is there a message you can send or a property you can set (of some object) that sets the "Active" UIViewController for the app?

    Read the article

  • Multiple View App shows Blank Screen in Simulator

    - by Brett Coburn
    Hello; I am developing a simple app that first shows a menu screen, and when a button is pressed, a game screen appears. I was able to develop the game screen without any issues, but when I changed the code to first display the menu, the simulator showed a blank screen. I've read all the articles on connecting views with IB but I can't figure this out. Any help would be appreciated. This is my code: // Pong_Multiple_ViewAppDelegate.h // Pong Multiple View // // Created by Brett on 10-05-19. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import <UIKit/UIKit.h> @class MenuViewController; @interface Pong_Multiple_ViewAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; MenuViewController *navigationController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet MenuViewController *navigationController; @end // // Pong_Multiple_ViewAppDelegate.m // Pong Multiple View // // Created by Brett on 10-05-19. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import "Pong_Multiple_ViewAppDelegate.h" #import "MenuViewController.h" @implementation Pong_Multiple_ViewAppDelegate @synthesize window; @synthesize navigationController; - (void)application:(UIApplication *)application{ // Override point for customization after application launch [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; } - (void)dealloc { [navigationController release]; [window release]; [super dealloc]; } @end // // MenuViewController.h // Pong Multiple View // // Created by Brett on 10-05-19. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> #import "GameViewController.h" @interface MenuViewController : UIViewController { GameViewController *gameViewController; IBOutlet UIButton *gameButton; } @property(nonatomic, retain) GameViewController *gameViewController; @property(nonatomic, retain) UIButton *gameButton; -(IBAction)switchPage:(id)sender; @end // // MenuViewController.m // Pong Multiple View // // Created by Brett on 10-05-19. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "MenuViewController.h" #import "GameViewController.h" @implementation MenuViewController @synthesize gameViewController; @synthesize gameButton; -(IBAction)switchPage:(id)sender{ if (self.gameViewController==nil) { GameViewController *gameView = [[GameViewController alloc]initWithNibName:@"GameView" bundle:[NSBundle mainBundle]]; self.gameViewController= gameView; [gameView release]; } [self.navigationController pushViewController:self.gameViewController animated:YES]; } .... @end My code also includes classes: GameViewController.h, GameViewController.m, and nib files: MenuView.xib, and GameView.xib Thanks, B

    Read the article

  • UIImageWriteToSavedPhotosAlbum showing memory leak with iPhone connected to Instruments

    - by user168739
    Hi, I'm using version 3.0.1 of the SDK. With the iPhone connected to Instruments I'm getting a memory leak when I call UIImageWriteToSavedPhotosAlbum. Below is my code: NSString *gnTmpStr = [NSString stringWithFormat:@"%d", count]; UIImage *ganTmpImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:gnTmpStr ofType:@"jpg"]]; // Request to save the image to camera roll UIImageWriteToSavedPhotosAlbum(ganTmpImage, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil); and the selector method - (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { NSString *message; NSString *title; if (!error) { title = @"Wallpaper"; message = @"Wallpaper Saved"; } else { title = @"Error"; message = [error description]; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } Am I forgetting to release something once the image has been saved and the selector method imageSavedToPhotosAlbum is called? Or is there a possible known issue with UIImageWriteToSavedPhotosAlbum? Here is the stack trace from Instruments: Leaked Object: GeneralBlock-3584 size: 3.50 KB 30 MyApp start 29 MyApp main /Users/user/Desktop/MyApp/main.m:14 28 UIKit UIApplicationMain 27 UIKit -[UIApplication _run] 26 GraphicsServices GSEventRunModal 25 CoreFoundation CFRunLoopRunInMode 24 CoreFoundation CFRunLoopRunSpecific 23 GraphicsServices PurpleEventCallback 22 UIKit _UIApplicationHandleEvent 21 UIKit -[UIApplication sendEvent:] 20 UIKit -[UIWindow sendEvent:] 19 UIKit -[UIWindow _sendTouchesForEvent:] 18 UIKit -[UIControl touchesEnded:withEvent:] 17 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:] 16 UIKit -[UIControl sendAction:to:forEvent:] 15 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:] 14 UIKit -[UIApplication sendAction:to:from:forEvent:] 13 CoreFoundation -[NSObject performSelector:withObject:withObject:] 12 UIKit -[UIBarButtonItem(Internal) _sendAction:withEvent:] 11 UIKit -[UIApplication sendAction:to:from:forEvent:] 10 CoreFoundation -[NSObject performSelector:withObject:withObject:] 9 MyApp -[FlipsideViewController svPhoto] /Users/user/Desktop/MyApp/Classes/FlipsideViewController.m:218 8 0x317fa528 7 0x317e3628 6 0x317e3730 5 0x317edda4 4 0x3180fc74 3 Foundation +[NSThread detachNewThreadSelector:toTarget:withObject:] 2 Foundation -[NSThread start] 1 libSystem.B.dylib pthread_create 0 libSystem.B.dylib malloc I did a test with a new project and only added this code below in the viewDidLoad: NSString *gnTmpStr = [NSString stringWithFormat:@"DefaultTest"]; UIImage *ganTmpImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:gnTmpStr ofType:@"png"]]; // Request to save the image to camera roll UIImageWriteToSavedPhotosAlbum(ganTmpImage, nil, nil, nil); The same leak shows up right after the app loads Thank you for the help. Bryan

    Read the article

  • Looking for Reachability (2.0) Use Case Validation

    - by user350243
    There is so much info out there on using Apple's Reachability example, and so much is conflicting. I'm trying to find out of I'm using it (Reachability 2.0) correctly below. My App use case is this: If an internet connection is available through any means (wifi, LAN, Edge, 3G, etc.) a UIButton ("See More") is visible on various views. If no connection, the button is not visible. The "See More" part is NOT critical in any way to the app, it's just an add-on feature. "See More" could be visible or not anytime during the application lifecycle as connection is established or lost. Here's how I did it - Is this correct and/or is there a better way? Any help is Greatly Appreciated! lq // AppDelegate.h #import "RootViewController.h" @class Reachability; @interface AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UINavigationController *navigationController; RootViewController *rootViewController; Reachability* hostReach; // NOT USED: Reachability* internetReach; // NOT USED: Reachability* wifiReach; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @property (nonatomic, retain) IBOutlet RootViewController *rootViewController; @end // AppDelegate.m #import "AppDelegate.h" #import "Reachability.h" #define kHostName @"www.somewebsite.com" @implementation AppDelegate @synthesize window; @synthesize navigationController; @synthesize rootViewController; - (void) updateInterfaceWithReachability: (Reachability*) curReach { if(curReach == hostReach) { NetworkStatus netStatus = [curReach currentReachabilityStatus]; BOOL connectionRequired = [curReach connectionRequired]; // Set a Reachability BOOL value flag in rootViewController // to be referenced when opening various views if ((netStatus != ReachableViaWiFi) && (netStatus != ReachableViaWWAN)) { rootViewController.bConnection = (BOOL *)0; } else { rootViewController.bConnection = (BOOL *)1; } } } - (void) reachabilityChanged: (NSNotification* )note { Reachability* curReach = [note object]; NSParameterAssert([curReach isKindOfClass: [Reachability class]]); [self updateInterfaceWithReachability: curReach]; } - (void)applicationDidFinishLaunching:(UIApplication *)application { // NOTE: #DEFINE in Reachability.h: // #define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification" [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil]; hostReach = [[Reachability reachabilityWithHostName: kHostName] retain]; [hostReach startNotifer]; [self updateInterfaceWithReachability: hostReach]; [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; } - (void)dealloc { [navigationController release]; [rootViewController release]; [window release]; [super dealloc]; } @end

    Read the article

  • Does a hidden UIViewController consume any resources (iPhone)?

    - by MrDatabase
    My simple iPhone game has two basic "screens": home screen (UIViewController subclass) game screen (UIWindow w/ EAGLLayer where all the OpenGL drawing happens) Currently when the user taps "Play" on the homescreen the UIViewController is just hidden and the game screen is revealed. When the game is over the homescreen UIViewController is unhidden. Does the hidden UIViewController consume any resources when it's hidden?

    Read the article

  • iPhone Tab Bar application crash

    - by Mark Szymanski
    I have an application that uses a tab bar and whenever it launches it crashes and gives me the following error and stack trace: 2010-04-22 16:15:03.390 iCrushCans[59858:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIWindow 0x3e051a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key rootViewController.' 2010-04-22 16:15:03.392 iCrushCans[59858:207] Stack: ( 29680731, 2425423113, 29839809, 305768, 304309, 2957847, 4641908, 29583663, 4636459, 4644727, 2805842, 2844630, 2833204, 2815615, 2842721, 37776729, 29465472, 29461576, 2809365, 2846639 ) Thanks in advance!

    Read the article

  • iPhone: no way to draw on screen outside drawRect?

    - by Seva Alekseyev
    Is there a way to draw on the iPhone screen (on a UIView in a UIWindow) outside of that view's drawRect() method? If so, how do I obtain the graphics context? The graphics guide mentions class NSGraphicsContext, but the relevant chapter seems like a blind copy/paste from Mac OS X docs, and there's no such class in iPhone SDK.

    Read the article

  • How to retreive Bundle Version in a label from project test-Info.plist in iphone?

    - by aman-gupta
    Hi, Here I m pasting my codes where i want to retrive Bundle version from my test-Info.plist. // // testAppDelegate.h // test // // Created by Fortune1 on 20/04/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import <UIKit/UIKit.h> @class testViewController; @interface testAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; testViewController *viewController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet testViewController *viewController; @end ////////////// // // testAppDelegate.m // test // // Created by Fortune1 on 20/04/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import "testAppDelegate.h" #import "testViewController.h" @implementation testAppDelegate @synthesize window; @synthesize viewController; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } @end ///////////////////// // // testViewController.h // test // // Created by Fortune1 on 20/04/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import <UIKit/UIKit.h> @interface testViewController : UIViewController { UILabel *label; } @property(nonatomic,retain) IBOutlet UILabel *label; @end /////////////////////// // // testViewController.m // test // // Created by Fortune1 on 20/04/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import "testViewController.h" @implementation testViewController @synthesize label; /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"test-info" ofType:@"plist"]; NSString *versionString = [NSString stringWithFormat:@"v%d", [plistData objectForKey:@"Bundle version"]]; label.text = versionString; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end But still I got null value where i m wrong please help me out Thanks in advance

    Read the article

  • Methods in Customized View did not get invoke in AppDelegate, Why?

    - by NorthKyut
    I want the methods pauseGame in customized UIView - MyGameView get invoked when the phone is locked or interrupted. So I have a pauseGame method but it can't stop the timer when user lock screen (command+L). The lock screen did appear but the game still running at the background. So I added the testPause method to MyGameView and MyGameAppDelegate and and put a breakpoint to debug it. When screen locked it, the screen lock appeared and the code did stop at the breakpoint. But when I tried to step into the testPause method, it didn't take me to the method in MyGameView (it just passed it, not skipped) and no message was printed on terminal by NSLog. Why? What did I miss? // // MyGameAppDelegate.h // MyGame // #import <UIKit/UIKit.h> @class MyGameViewController; @class MyGameView; @interface MyGameAppDelegate : NSObject { UIWindow *window; MyGameViewController *viewController; MyGameView *view; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet MyGameViewController *viewController; @property (nonatomic, retain) IBOutlet MyGameView *view; @end // // MyGameAppDelegate.m // MyGame // #import "MyGameAppDelegate.h" #import "MyGameViewController.h" #import "MyGameView.h" @implementation MyGameAppDelegate @synthesize window; @synthesize viewController; @synthesize view; - (void)applicationWillResignActive:(UIApplication *)application { /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */ [view pauseGame]; [view testPause]; } @end // // MyGameView.h // MyGame @interface MyGameView : UIView { - (void)pauseGame; - (void)testPause; @end // // MyGameView.m // MyGame // #import "MyGameView.h" #import "AtlasSprite.h" #import "MyGameViewController.h" #import "SecondViewController.h" @implementation MyGameView - (void)pauseGame { [theTimer invalidate]; theTimer = nil; } - (void)testPause{ NSLog(@"TestPause"); } @end

    Read the article

  • There's @interface in my @implementation — why is that?

    - by Mark McDonald
    This is a pretty noobish question – I'm looking at some Cocoa sample code and there's @interface blocks in the .m files as well as the headers. For instance, in the AppDelegate class header, a UIWindow and UI navigation are defined as instance variables, but the @property declarations are actually made in the implementation file. Is there a functional reason for this, is it a stylistic choice, or… ?

    Read the article

  • Trouble with touch events on iPhone

    - by MrDatabase
    I'm making a simple 2D game for iPhone. Think of the game as a ball on the screen that goes up while the user is touching the screen and falls down when the user stops touching the screen. The ball starts moving up in touchesBegan:withEvent and starts moving down in touchesEnded:withEvent. This works fine almost all the time. However on occasion the ball will keep moving up after the user stops touching... or the ball will keep moving down while the user is touching. Why is this happening? Just fyi the ball is drawn on a UIWindow. The taps are handled by a UIImageview subclass that's clearColor and takes up the entire screen. This "touchLayer" is also moved to the front of the window in the game loop. Any idea why this control scheme occasionally fails? Perhaps the touch events just aren't firing? Or they're fired out of order? Cheers!

    Read the article

  • How to use NSMutableDictionary to store and retrieve data

    - by TechFusion
    I have created Window Based application and tab bar controller as root controller. My objective is to store Text Field data values in one tab bar VC and will be accessible and editable by other VC and also retrievable when application start. I am looking to use NSMutableDictionary class in AppDelegate so that I can access stored Data Values with keys. //TestAppDelegate.h extern NSString *kNamekey ; extern NSString *kUserIDkey ; extern NSString *kPasswordkey ; @interface TestAppDelegate :NSObject{ UIWindow *window; IBOutlet UITabBarController *rootController; NSMutableDictionary *outlineData ; } @property(nonatomic,retain)IBOutlet UIWindow *window; @property(nonatomic,retain)IBOutlet UITabBarController *rootController; @property(nonatomic,retain) NSMutableDictionary *outlineData ; @end //TestAppDelegate.m import "TestAppDelegate.h" NSString *kNamekey =@"Namekey"; NSString *kUserIDkey =@"UserIDkey"; NSString *kPasswordkey =@"Passwordkey"; @implemetation TestAppDelegate @synthesize outlineData ; -(void)applicationDidFinishLaunching:(UIApplication)application { NSMutableDictionary *tempMutableCopy = [[[NSUserDefaults standardUserDefaults] objectForKey:kRestoreLocationKey] mutableCopy]; self.outlineData = tempMutableCopy; [tempMutableCopy release]; if(outlineData == nil){ NSString *NameDefault = NULL; NSString *UserIDdefault= NULL; NSString *Passworddefault= NULL; NSMutableDictionary *appDefaults = [NSMutableDictionary dictionaryWithObjectsAndKeys: NameDefault, kNamekey , UserIDdefault, kUserIDkey , Passworddefault, kPasswordkey , nil]; self.outlineData = appDefaults; [appDefaults release]; } [window addSubview:rootController.view]; [window makeKeyAndVisible]; NSMutableDictionary *savedLocationDict = [NSMutableDictionary dictionaryWithObject:outlineData forKey:kRestoreLocationKey]; [[NSUserDefaults standardUserDefaults] registerDefaults:savedLocationDict]; [[NSUserDefaults standardUserDefaults] synchronize]; } -(void)applicationWillTerminate:(UIApplication *)application { [[NSUserDefaults standardUserDefaults] setObject:outlineData forKey:kRestoreLocationKey]; } @end Here ViewController is ViewController of Navigation Controller which is attached with one tab bar.. I have attached xib file with ViewController //ViewController.h @interface IBOutlet UITextField *Name; IBOutlet UITextField *UserId; IBOutlet UITextField *Password; } @property(retain,nonatomic) IBOutlet UITextField *Name @property(retain,nonatomic) IBOutlet UITextField *UserId; @property(retain,nonatomic) IBOutlet UITextField *Password; -(IBAction)Save:(id)sender; @end Here in ViewController.m, I am storing object values with keys. /ViewController.m -(IBAction)Save:(id)sender{ TestAppDelegate appDelegate = (TestAppDelegate)[[UIApplication sharedApplication] delegate]; [appDelegate.outlineData setObject:Name.text forKey:kNamekey ]; [appDelegate.outlineData setObject:UserId.text forKey:kUserIDkey ]; [appDelegate.outlineData setObject:Password.text forKey:kPasswordkey]; [[NSUserDefaults standardUserDefaults] synchronize]; } I am accessing stored object using following method. -(void)loadData { TabBarAppDelegate *appDelegate = (TabBarAppDelegate *)[[UIApplication sharedApplication] delegate]; Name = [appDelegate.outlineData objectForKey:kNamekey ]; UserId = [appDelegate.outlineData objectForKey:kUserIDkey ]; Password = [appDelegate.outlineData objectForKey:kPasswordkey]; [Name release]; [UserId release]; [Password release]; } I am getting EXEC_BAD_ACCESS in application. Where I am making mistake ? Thanks,

    Read the article

  • iPhone crash on CoreData save

    - by davetron5000
    This is a different situation than this question, as the solution provided doesn't work and the stack is different. Periodical crash when I save data using coredata. The stack trace isn't 100% clear on where this is happening, but I'm certain it's this routine that's being called. It's either the save: in this method or the one following. Code: -(void)saveWine { if ([self validInfo]) { Wine *wine = (Wine *)wineToEdit; if (wine == nil) { wine = (Wine *)[NSEntityDescription insertNewObjectForEntityForName:@"Wine" inManagedObjectContext:self.managedObjectContext]; } wine.uuid = [Utils createUUID]; wine.name = self.wineNameField.text; wine.vineyard = self.vineyardField.text; wine.vintage = [[self numberFormatter] numberFromString:self.vintageField.text]; wine.timeStamp = [NSDate date]; wine.rating = [NSNumber numberWithInt:self.ratingControl.selectedSegmentIndex]; wine.partnerRating = [NSNumber numberWithInt:self.partnerRatingControl.selectedSegmentIndex]; wine.varietal = self.currentVarietal; wine.tastingNotes = self.currentTastingNotes; wine.dateTasted = self.currentDateTasted; wine.tastingLocation = [[ReferenceDataAccessor defaultReferenceDataAccessor] addEntityForType:TASTING_LOCATION withName:self.currentWhereTasted]; id type = [[ReferenceDataAccessor defaultReferenceDataAccessor] entityForType:WINE_TYPE withOrdinal:self.typeControl.selectedSegmentIndex]; wine.type = type; NSError *error; NSLog(@"Saving %@",wine); if (![self.managedObjectContext save:&error]) { [Utils showAlertMessage:@"There was a problem saving your wine; try restarting the app" withTitle:@"Problem saving"]; NSLog(@"Error while saving new wine %@, %@", error, [error userInfo]); } } else { NSLog(@"ERROR - someone is calling saveWine with invalid info!!"); } } Code for addEntityForType:withName:: -(id)addEntityForType:(NSString *)type withName:(NSString *)name { if ([Utils isStringBlank:name]) { return nil; } id existing = [[ReferenceDataAccessor defaultReferenceDataAccessor] entityForType:type withName:name]; if (existing != nil) { NSLog(@"%@ with name %@ already exists",type,name); return existing; } NSManagedObject *newEntity = [NSEntityDescription insertNewObjectForEntityForName:type inManagedObjectContext:self.managedObjectContext]; [newEntity setValue:name forKey:@"name"]; NSError *error; if (![self.managedObjectContext save:&error]) { [Utils showAlertMessage:[NSString stringWithFormat:@"There was a problem saving a %@",type] withTitle:@"Database Probem"]; [Utils logErrorFully:error forOperation:[NSString stringWithFormat:@"saving new %@",type ]]; } return newEntity; } Stack trace: Thread 0 Crashed: 0 libSystem.B.dylib 0x311de2d4 __kill + 8 1 libSystem.B.dylib 0x311de2c4 kill + 4 2 libSystem.B.dylib 0x311de2b6 raise + 10 3 libSystem.B.dylib 0x311f2d72 abort + 50 4 libstdc++.6.dylib 0x301dea20 __gnu_cxx::__verbose_terminate_handler() + 376 5 libobjc.A.dylib 0x319a2594 _objc_terminate + 104 6 libstdc++.6.dylib 0x301dcdf2 __cxxabiv1::__terminate(void (*)()) + 46 7 libstdc++.6.dylib 0x301dce46 std::terminate() + 10 8 libstdc++.6.dylib 0x301dcf16 __cxa_throw + 78 9 libobjc.A.dylib 0x319a14c4 objc_exception_throw + 64 10 CoreData 0x3526e83e -[NSManagedObjectContext save:] + 1098 11 Wine Brain 0x0000651e 0x1000 + 21790 12 Wine Brain 0x0000525c 0x1000 + 16988 13 Wine Brain 0x00004894 0x1000 + 14484 14 Wine Brain 0x00008716 0x1000 + 30486 15 CoreFoundation 0x31477fe6 -[NSObject(NSObject) performSelector:withObject:withObject:] + 18 16 UIKit 0x338c14a6 -[UIApplication sendAction:to:from:forEvent:] + 78 17 UIKit 0x3395c7ae -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 86 18 CoreFoundation 0x31477fe6 -[NSObject(NSObject) performSelector:withObject:withObject:] + 18 19 UIKit 0x338c14a6 -[UIApplication sendAction:to:from:forEvent:] + 78 20 UIKit 0x338c1446 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26 21 UIKit 0x338c1418 -[UIControl sendAction:to:forEvent:] + 32 22 UIKit 0x338c116a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350 23 UIKit 0x338c19c8 -[UIControl touchesEnded:withEvent:] + 336 24 UIKit 0x338b734e -[UIWindow _sendTouchesForEvent:] + 362 25 UIKit 0x338b6cc8 -[UIWindow sendEvent:] + 256 26 UIKit 0x338a1fc0 -[UIApplication sendEvent:] + 292 27 UIKit 0x338a1900 _UIApplicationHandleEvent + 5084 28 GraphicsServices 0x35d66efc PurpleEventCallback + 660 29 CoreFoundation 0x314656f8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20 30 CoreFoundation 0x314656bc __CFRunLoopDoSource1 + 160 31 CoreFoundation 0x31457f76 __CFRunLoopRun + 514 32 CoreFoundation 0x31457c80 CFRunLoopRunSpecific + 224 33 CoreFoundation 0x31457b88 CFRunLoopRunInMode + 52 34 GraphicsServices 0x35d664a4 GSEventRunModal + 108 35 GraphicsServices 0x35d66550 GSEventRun + 56 36 UIKit 0x338d5322 -[UIApplication _run] + 406 37 UIKit 0x338d2e8c UIApplicationMain + 664 38 Wine Brain 0x000021ba 0x1000 + 4538 39 Wine Brain 0x00002184 0x1000 + 4484 I have no idea why my app's memory locations aren't being symbolocated, but the code paths lead to only two manavedObjectContext save: calls. The time this happend, addEntityForType was called all the way through, creating a new object for the "whereTasted" entity, before the final save: on the entire wine object. When I go through the same procedure again, it works fine. This leads me to believe it's something to do with the app having been run for a while when adding a new location, but I'm not sure. Any thoughts on how I can debug this and get more info the next time this happens?

    Read the article

  • Why does my UIWebView not Allow User Interaction?

    - by thomasmcgee
    Hi, I'm new to these forums so I apologize for my noobieness. I did as thorough a search as I could, but I couldn't find anyone else with this issue, applogise if this has been covered elsewhere. I've created a very simple example of my problem. I'm sure I'm missing something but I can't for the life of me figure out what. I'm creating a UIWebView and adding it to a custom view controller that inherits from UIViewController. When the app loads in the iPad simulator, the uiwebview loads the desired page, but the UIWebView is entirely unresponsive. The webview does not pan or scroll and none of the in page links can be clicked. However, if you change the orientation of the webview suddleny everything works. Thanks in advance for your help!! AppDelegate header #import <UIKit/UIKit.h> #import "EditorViewController.h" @interface FixEditorTestAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; EditorViewController *editorView; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) EditorViewController *editorView; @end AppDelegate Implementation #import "FixEditorTestAppDelegate.h" #import "EditorViewController.h" @implementation FixEditorTestAppDelegate @synthesize window; @synthesize editorView; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"application is loading"); editorView = [[EditorViewController alloc] init]; [window addSubview:[editorView view]]; [window makeKeyAndVisible]; return YES; } - (void)dealloc { [window release]; [editorView release]; [super dealloc]; } @end View Controller header #import <UIKit/UIKit.h> @interface EditorViewController : UIViewController <UIWebViewDelegate> { UIWebView *webView; } @property (nonatomic, retain) UIWebView *webView; @end View Controller Implementation #import "EditorViewController.h" @implementation EditorViewController @synthesize webView; /* // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization } return self; } */ // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { NSLog(@"loadView called"); UIView *curView = [[UIView alloc] init]; webView = [[UIWebView alloc] init]; webView.frame = CGRectMake(20, 40, 728, 964); webView.delegate = self; webView.backgroundColor = [UIColor redColor]; [curView addSubview: webView]; self.view = curView; [curView release]; } //Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"viewDidLoad called"); NSURL *url = [[NSURL alloc] initWithString:@"http://www.nytimes.com"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; [webView loadRequest:request]; [url autorelease]; [request release]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Overriden to allow any orientation. return YES; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { webView.delegate = nil; [webView release]; [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } @end

    Read the article

  • Passing Variables between views / view controllers

    - by Dan
    Hi I'm new to ObjectiveC / IPhoneSDK and I'm informally trying to study it on my own. What I'm basically trying to do is from one view there are 12 zodiac signs. When a user clicks one, it proceeds to the second view (with animation) and loads the name of the zodiac sign it clicked in a UILabel, that's it. Here are my codes: Lovescopes = 1st page Horoscopes = 2nd page Lovescopes4AppDelegate.h #import <UIKit/UIKit.h> #import "HoroscopesViewController.h" #import "Lovescopes4AppDelegate.h" @class Lovescopes4ViewController; @interface Lovescopes4AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; Lovescopes4ViewController *viewController; HoroscopesViewController *horoscopesViewController; } -(void)loadHoroscope; -(void)loadMainPage; @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet Lovescopes4ViewController *viewController; @property (nonatomic, retain) HoroscopesViewController *horoscopesViewController; @end Lovescopes4AppDelegate.m #import "Lovescopes4AppDelegate.h" #import "Lovescopes4ViewController.h" @implementation Lovescopes4AppDelegate @synthesize window; @synthesize viewController; @synthesize horoscopesViewController; -(void)loadHoroscope { HoroscopesViewController *aHoroscopeViewController = [[HoroscopesViewController alloc] initWithNibName:@"HoroscopesViewController" bundle:nil]; [self setHoroscopesViewController:aHoroscopeViewController]; [aHoroscopeViewController release]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES]; [viewController.view removeFromSuperview]; [self.window addSubview:[horoscopesViewController view]]; [UIView commitAnimations]; } -(void)loadMainPage { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:NO]; [horoscopesViewController.view removeFromSuperview]; [self.window addSubview:[viewController view]]; [UIView commitAnimations]; [horoscopesViewController release]; horoscopesViewController = nil; } - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } @end Lovescopes4ViewController.h #import <UIKit/UIKit.h> #import "HoroscopesViewController.h" @interface Lovescopes4ViewController : UIViewController { HoroscopesViewController *hvc; } -(IBAction)loadAries; @property (nonatomic, retain) HoroscopesViewController *hvc; @end Lovescope4ViewController.m #import "Lovescopes4ViewController.h" #import "Lovescopes4AppDelegate.h" @implementation Lovescopes4ViewController @synthesize hvc; -(IBAction)loadAries { NSString *selected =@"Aries"; [hvc loadZodiac:selected]; Lovescopes4AppDelegate *mainDelegate = (Lovescopes4AppDelegate *) [[UIApplication sharedApplication] delegate]; [mainDelegate loadHoroscope]; } HoroscopesViewController.h #import <UIKit/UIKit.h> @interface HoroscopesViewController : UIViewController { IBOutlet UILabel *zodiacLabel; } -(void)loadZodiac:(id)zodiacSign; -(IBAction)back; @property (nonatomic, retain) IBOutlet UILabel *zodiacLabel; @end HoroscopesViewController.m #import "HoroscopesViewController.h" #import "Lovescopes4AppDelegate.h" @implementation HoroscopesViewController @synthesize zodiacLabel; /* // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */ /* // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } */ /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ -(void)loadZodiac:(id)zodiacSign { zodiacLabel.text = [NSString stringWithFormat: @"%@", zodiacSign]; } -(IBAction)back { Lovescopes4AppDelegate *mainDelegate = (Lovescopes4AppDelegate *) [[UIApplication sharedApplication] delegate]; [mainDelegate loadMainPage]; }

    Read the article

  • When my UIViewController accesses an NSArray in my AppDelegate from an IBAction it crashes the progr

    - by JasonClark
    I have a couple UIViewControllers that I am trying to access an array inside my AppDelegate. When I use an IBAction UIButton and in that method I access my AppDelegate my program dies silently. Nothing in output or the debugger, it just stops. If I run it several times I can see that it is failing to access the array properly. To investigate this problem I created a very basic app. In my AppDelegate.h I declared and set properties for the array #import <UIKit/UIKit.h> @class MyViewController; @interface MyAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; MyViewController *viewController; NSArray *images; } @property (nonatomic, retain) NSArray *images; @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet MyViewController *viewController;` In the AppDelegate.m I synthesised and initialized the NSArray (Also made sure the images were added to the Resources folder). @synthesize images; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { images = [NSArray arrayWithObjects: [[NSBundle mainBundle] pathForResource:@"bamboo_nw" ofType:@"jpg"], ..... nil]; NSLog(@"init images size:%i",[images count]); [window addSubview:viewController.view]; [window makeKeyAndVisible]; return YES; } In my UIViewController.h I added class, imported header file, declared, and set properties for my AppDelegate pointer. #import <UIKit/UIKit.h> #import "MyAppDelegate.h" @class MyAppDelegate; @interface MyViewController : UIViewController { MyAppDelegate *mainDelegate; IBOutlet UIButton mybutton; } @property (nonatomic, retain) MyAppDelegate mainDelegate; @property (nonatomic, retain) UIButton *mybutton; -(IBAction) doSomething;` In my UIViewController.m I synthesize and assign my AppDelegate. I set up an IBAction that will log the same count of the NSArray from the AppDelegate. #import "MyViewController.h" #import "MyAppDelegate.h" @implementation MyViewController @synthesize mybutton; - (void)viewDidLoad { mainDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; NSLog(@"vdl images size:%i",[mainDelegate.images count]); [super viewDidLoad]; } -(IBAction) doSomething { NSLog(@"ds images size:%i",[mainDelegate.images count]); } I print the size of the NSArray in the AppDelegate when I create it, in the ViewController when I first assign my AppDelegate pointer, and then as a result of my IBAction. I find that everytime I hit the button the program dies. On the third time I hit the button, I saw that it ran my IBAction but printed my array size as 1 instead of 8. Am I missing something? Also, why don't I get stack traces or anything, the debugger just dies silently? Thanks in advance for any help! Debugger Console output for 3 runs: [Session started at 2010-05-10 06:21:32 -0700.] 2010-05-10 06:21:44.865 My[59695:207] init images size:8 2010-05-10 06:21:47.246 My[59695:207] vdl images size:8 [Session started at 2010-05-10 06:22:15 -0700.] 2010-05-10 06:22:18.920 My[59704:207] init images size:8 2010-05-10 06:22:19.043 My[59704:207] vdl images size:8 [Session started at 2010-05-10 06:22:23 -0700.] 2010-05-10 06:22:25.966 My[59707:207] init images size:8 2010-05-10 06:22:26.017 My[59707:207] vdl images size:8 2010-05-10 06:22:27.814 My[59707:207] ds images size:1

    Read the article

  • CoreData: managedObjectContext not being created

    - by PruitIgoe
    I had to add core data to an existing project but I am having issues with the managedObjectContext... in prefix.pch I have this: #import <Availability.h> #ifndef __IPHONE_5_0 #warning "This project uses features only available in iOS SDK 5.0 and later." #endif #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> #endif ... in my appDelegate.h I have this: #import <UIKit/UIKit.h> #import "AppViewController.h" #import "DDLog.h" #import "DDASLLogger.h" #import "DDFileLogger.h" #import "DDTTYLogger.h" #import "KIP_LogManager.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> { DDFileLogger* fileLogger; /*coredata*/ NSManagedObjectModel* managedObjectModel; NSManagedObjectContext* managedObjectContext; NSPersistentStoreCoordinator* persistentStoreCoordinator; } @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) AppViewController* viewController; @property (readonly, strong, nonatomic) NSManagedObjectContext* managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel* managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator* persistentStoreCoordinator; - (void)setupLogging; - (NSString *)applicationDocumentsDirectory; in appDelegate.m this: @synthesize managedObjectContext = _managedObjectContext; @synthesize managedObjectModel = _managedObjectModel; @synthesize persistentStoreCoordinator = _persistentStoreCoordinator; ... - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //establish lumberjack logging [self setupLogging]; DDLogVerbose(@"\n\n*********************\nNEW LOG SESSION\n**********************\n\n"); //set root view controller self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.viewController = [[AppViewController alloc] init]; self.window.rootViewController = self.viewController; self.viewController.managedObjectContext = _managedObjectContext; return YES; } ... #pragma mark - CoreData Stack - (NSManagedObjectContext *)managedObjectContext { if (_managedObjectContext != nil) { return _managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { _managedObjectContext = [[NSManagedObjectContext alloc] init]; [_managedObjectContext setPersistentStoreCoordinator:coordinator]; } return _managedObjectContext; } // Returns the managed object model for the application. // If the model doesn't already exist, it is created from the application's model. - (NSManagedObjectModel *)managedObjectModel { if (_managedObjectModel != nil) { return _managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"SPI_PAC" withExtension:@"momd"]; _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return _managedObjectModel; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSMutableString* strDocsDirector = [[NSMutableString alloc] initWithString:[self applicationDocumentsDirectory]]; [strDocsDirector appendString:@"/SPI_PAC.sqlite"]; NSURL* storeURL = [NSURL URLWithString:strDocsDirector]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { /*Error for store creation should be handled in here*/ } return persistentStoreCoordinator; } - (NSString *)applicationDocumentsDirectory { return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; } in the view controller, viewDidLoad I am logging the passed managedObjectContext and am getting null returned. Obviously I am missing something but not sure what? In viewcontroller.h I have: @property (nonatomic, retain) NSManagedObjectModel* managedObjectModel; @property (nonatomic, retain) NSManagedObjectContext* managedObjectContext; @property (nonatomic, retain) NSPersistentStoreCoordinator* persistentStoreCoordinator; and in the viewcontroller.m: @synthesize managedObjectContext = managedObjectContext; ... DDLogVerbose(@"%@", managedObjectContext);

    Read the article

  • UIView to Form Sheet flip animation rotation issue

    - by GSD
    I have this view to form sheet flip animation that works great in portrait mode but not in any other orientations. In my code, I use it with a UIView embedded in another UIView, which is in the root view. The animation will be rotated. Anyone has an idea why? - (void)presentModalViewControllerWithFlipAnimation:(UIViewController *)modalViewController fromView:(UIView *)fromView { UIWindow* window = [[UIApplication sharedApplication] windows][0]; _fromViewSnapshot = [[UIImageView alloc] initWithFrame:fromView.bounds]; UIGraphicsBeginImageContext(fromView.bounds.size); [fromView.layer renderInContext:UIGraphicsGetCurrentContext()]; [_fromViewSnapshot setImage:UIGraphicsGetImageFromCurrentImageContext()]; [_fromViewSnapshot sizeToFit]; UIGraphicsEndImageContext(); _fromViewSnapshot.autoresizesSubviews = YES; _fromViewSnapshot.frame = [fromView.superview convertRect:fromView.frame toView:window]; [window addSubview:_fromViewSnapshot]; fromView.hidden = YES; modalViewController.modalPresentationStyle = UIModalPresentationFormSheet; [self presentViewController:modalViewController animated:NO completion:nil]; UIView __weak *presentedView = modalViewController.view.superview; UIGraphicsBeginImageContext(presentedView.bounds.size); [presentedView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage* modalSnapshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIView __weak *presentationSuperview = presentedView.superview; [presentedView removeFromSuperview]; UIImageView* presentationSnapshotView = [[UIImageView alloc] initWithImage:modalSnapshot]; presentationSnapshotView.autoresizingMask = UIViewAutoresizingNone; [_fromViewSnapshot.superview bringSubviewToFront:_fromViewSnapshot]; [UIView animateWithDuration:kFlipAnimationScaleSpeed delay:0 options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionBeginFromCurrentState animations: ^{ [UIView animateWithDuration:kFlipAnimationScaleSpeed delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations: ^{ _fromViewSnapshot.frame = [_fromViewSnapshot.superview convertRect:presentedView.frame fromView:presentationSuperview]; } completion:nil]; } completion:^(BOOL finished) { [UIView setAnimationBeginsFromCurrentState:YES]; [UIView transitionWithView:_fromViewSnapshot duration:kFlipAnimationSpeed options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionTransitionFlipFromRight animations: ^{ presentationSnapshotView.frame = _fromViewSnapshot.bounds; [_fromViewSnapshot addSubview:presentationSnapshotView]; } completion:^(BOOL finished) { [presentationSuperview addSubview:presentedView]; [presentationSnapshotView removeFromSuperview]; [_fromViewSnapshot removeFromSuperview]; }]; }]; } - (void)dismissViewControllerWithFlipAnimation:(UIView*)fromView completion:(void (^)(void))completion { UIWindow* window = [[UIApplication sharedApplication] windows][0]; UIView __weak *presentedView = self.presentedViewController.view.superview; UIGraphicsBeginImageContext(presentedView.bounds.size); [presentedView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage* modalSnapshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [presentedView removeFromSuperview]; UIImageView* presentationSnapshotView = [[UIImageView alloc] initWithImage:modalSnapshot]; presentationSnapshotView.autoresizingMask = UIViewAutoresizingNone; presentationSnapshotView.frame = presentedView.frame; [window addSubview:presentationSnapshotView]; [UIView animateWithDuration:kFlipAnimationScaleSpeed delay:0 options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionBeginFromCurrentState animations: ^{ [UIView animateWithDuration:kFlipAnimationScaleSpeed delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations: ^{ presentationSnapshotView.frame = [fromView.superview convertRect:fromView.frame toView:window]; } completion:nil]; } completion:^(BOOL finished) { [UIView setAnimationBeginsFromCurrentState:YES]; [UIView transitionWithView:presentationSnapshotView duration:kFlipAnimationSpeed options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionTransitionFlipFromLeft animations: ^{ _fromViewSnapshot.frame = presentationSnapshotView.bounds; [presentationSnapshotView setImage:[(UIImageView*)_fromViewSnapshot image]]; [self dismissViewControllerAnimated:NO completion:nil]; } completion:^(BOOL finished) { [presentationSnapshotView removeFromSuperview]; _fromViewSnapshot = nil; completion(); }]; }]; }

    Read the article

  • Iphone SDK - adding UITableView to UIView

    - by Shashi
    Hi, I am trying to learn how to use different views, for this sample test app, i have a login page, upon successful logon, the user is redirected to a table view and then upon selection of an item in the table view, the user is directed to a third page showing details of the item. the first page works just fine, but the problem occurs when i go to the second page, the table shown doesn't have title and i cannot add title or toolbar or anything other than the content of the tables themselves. and when i click on the item, needless to say nothing happens. no errors as well. i am fairly new to programming and have always worked on Java but never on C(although i have some basic knowledge of C) and Objective C is new to me. Here is the code. import @interface NavigationTestAppDelegate : NSObject { UIWindow *window; UIViewController *viewController; IBOutlet UITextField *username; IBOutlet UITextField *password; IBOutlet UILabel *loginError; //UINavigationController *navigationController; } @property (nonatomic, retain) IBOutlet UIViewController *viewController; @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITextField *username; @property (nonatomic, retain) IBOutlet UITextField *password; @property (nonatomic, retain) IBOutlet UILabel *loginError; -(IBAction) login; -(IBAction) hideKeyboard: (id) sender; @end import "NavigationTestAppDelegate.h" import "RootViewController.h" @implementation NavigationTestAppDelegate @synthesize window; @synthesize viewController; @synthesize username; @synthesize password; @synthesize loginError; pragma mark - pragma mark Application lifecycle -(IBAction) hideKeyboard: (id) sender{ [sender resignFirstResponder]; } (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after app launch //RootViewController *rootViewController = [[RootViewController alloc] init]; //[window addSubview:[navigationController view]]; [window addSubview:[viewController view]]; [window makeKeyAndVisible]; return YES; } -(IBAction) login { RootViewController *rootViewController = [[RootViewController alloc] init]; //NSString *user = [[NSString alloc] username. if([username.text isEqualToString:@"test"]&&[password.text isEqualToString:@"test"]){ [window addSubview:[rootViewController view]]; //[window addSubview:[navigationController view]]; [window makeKeyAndVisible]; //rootViewController.awakeFromNib; } else { loginError.text = @"LOGIN ERROR"; [window addSubview:[viewController view]]; [window makeKeyAndVisible]; } } (void)applicationWillTerminate:(UIApplication *)application { // Save data if appropriate } pragma mark - pragma mark Memory management (void)dealloc { //[navigationController release]; [viewController release]; [window release]; [super dealloc]; } @end import @interface RootViewController : UITableViewController { IBOutlet NSMutableArray *views; } @property (nonatomic, retain) IBOutlet NSMutableArray * views; @end // // RootViewController.m // NavigationTest // // Created by guest on 4/23/10. // Copyright MyCompanyName 2010. All rights reserved. // import "RootViewController.h" import "OpportunityOne.h" @implementation RootViewController @synthesize views; //@synthesize navigationViewController; pragma mark - pragma mark View lifecycle (void)viewDidLoad { views = [ [NSMutableArray alloc] init]; OpportunityOne *opportunityOneController; for (int i=1; i<=20; i++) { opportunityOneController = [[OpportunityOne alloc] init]; opportunityOneController.title = [[NSString alloc] initWithFormat:@"Opportunity %i",i]; [views addObject:[NSDictionary dictionaryWithObjectsAndKeys: [[NSString alloc] initWithFormat:@"Opportunity %i",i], @ "title", opportunityOneController, @"controller", nil]]; self.title=@"GPS"; } /*UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init]; temporaryBarButtonItem.title = @"Back"; self.navigationItem.backBarButtonItem = temporaryBarButtonItem; [temporaryBarButtonItem release]; */ //self.title =@"Global Platform for Sales"; [super viewDidLoad]; //[temporaryBarButtonItem release]; //[opportunityOneController release]; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; } pragma mark - pragma mark Table view data source // Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [views count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. cell.textLabel.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"]; return cell; } pragma mark - pragma mark Table view delegate (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"]; UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"]; [[self navigationController] pushViewController:targetViewController animated:YES]; } pragma mark - pragma mark Memory management (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Relinquish ownership any cached data, images, etc that aren't in use. } (void)viewDidUnload { // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. // For example: self.myOutlet = nil; } (void)dealloc { [views release]; [super dealloc]; } @end Wow, i was finding it real hard to post the code. i apologize for the bad formatting, but i just couldn't get past the formatting rules for this text editor. Thanks, Shashi

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >