Search Results

Search found 664 results on 27 pages for 'viewdidload'.

Page 2/27 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • didSelectRowAtIndexPath being called after viewDidLoad of the called view

    - by Serguei Fedorov
    I am trying to pass variables over to the new view. I have the following code: appDelegate *dataCenter = (AppDelegate*)[[UIApplication sharedApplication] delegate]; dataCenter.myVariable = [array objectAtIndex:indexPath.row]; in the didSelectRowAtIndexPath of the calling view. However, the issue that I have is that this variable is empty in the vewDidLoad function of the next view, simply because it fired off BEFORE the didSelectRowAtIndexPath of the calling view. I am using storyboard to link the views together. Both are UITableView. If I hit back and then reselect the table element it is then set, granted that by the time I hit back and then selected again, the variable got set. Is there any way to for the order of execution? I really don't want to do UI view switching on the back end. Any help is greatly appreciated!

    Read the article

  • Is it possible to have a sound play before/during the splash screen?

    - by Jeff
    My app takes a few seconds to load and I have a splash screen. Once "viewDidLoad" I have a little sound play. I feel that the sound would be in better use if it started playing when the splash screen popped up. Is it possible to have a sound start before/during the splash screen? Here is my code: (under viewDidLoad) NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"intorSound" ofType: @"aif"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath]; player = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil]; [player setVolume: soundVolumeValue]; // available range is 0.0 through 1.0 [player play]; [fileURL release]; Thank you for your time!

    Read the article

  • Storing and loading a subtitle of an annotation with NSUserDefualts

    - by Krismutt
    Happy new year everybody! Basically, what I try to do is to save a subtitle to an annotation when the application terminates. When the application starts again I want this stored subtitle to show up in the callout of the annotation again. What am I doing wrong? I just can't get it to work... storeLocation.m - (void)setCoordinate:(CLLocationCoordinate2D)coor { MKReverseGeocoder *geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:coor] autorelease]; geocoder.delegate = self; coordinate = coor; [geocoder start]; NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults]; [userDef setValue:subtitle forKey:@"SavedAddress"]; [userDef synchronize]; NSLog(@"Sparade adress"); } mainViewController.m -(void)viewDidLoad { NSString *savedAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"SavedAddress"]; if (savedAddress) { // what code should I add here // so that the subtitle shows up // when the application launches? } } Would really appreciate some help with this one... Thanks in advance!

    Read the article

  • updating plist file on launch of application

    - by Josh Turnage
    Hi. I have an app that reads in a plist file from the resources folder. I have looked for about 5 hours for a solution to hosting my plist file on my freewebs acount and have the application update the plist file on launch. Can anyone help me please. I will post my code if you ask. I am just not sure what you need to see now.

    Read the article

  • Isn't it better to create the subview hierarchy in -viewDidLoad rather than in -loadView?

    - by dontWatchMyProfile
    The docs say that the whole subview hierarchy can be created in -loadView. But there's also this -viewDidLoad method which sounds nice to ovewrite for actually building the hierarchy, when the view loaded. I guess it's a matter of taste only. But maybe doing so in -viewDidLoad hast the advantage that the view controller already adjusted the frame of the view correctly to accomodate for the status bar or any other kind of bar like tab bar or tool bar?

    Read the article

  • Iphone SDK array initlised at viewdidload and released at dealloc is causing leak?

    - by Skeep
    Hi All, I am new to iphone development and i am getting ready to submit my first app. I have an array initlised at viewdidload and released at dealloc, however it is causing a leak. My question is why would this happen is it because the dealloc has not run? My Code is as follows the NSMutableArray called listOfItems is referenced in my .h file for the UITableView. The listOfItems array is used to populate the table. In the viewDidLoad method i have this code listOfItems = [[NSMutableArray alloc] init]; and in the dealloc i have: [listOfItems release]; When watching leaks in instruments I get a NSArray leak which when I drill down points to the line: listOfItems = [[NSMutableArray alloc] init]; Am i putting all this in the right place? Thanks

    Read the article

  • iOS5: Confusion with loadview and init and instance variables

    - by user743550
    I'm new to iOS5 and storyboarding. I noticed that if I declare an instance variables inside my viewcontroller .h file and set the values inside my init of .m file of my viewcontroller, whe the view of the viewcontroller is displayed, my instance variables show null inside viewDidLoad. In order for me to get myvariables, I'd need to do [self init] inside viewDidLoad. My questions are: @interface tableViewController : UITableViewController { NSMutableArray *myvariable; } @end @implementation tableViewController -(id)init { myvariable = [[NSMutableArray alloc]initWithObjects:@"Hi2",@"Yo2",@"whatsup2", nil]; } - (void)viewDidLoad { NSLog(@"%@",myvariable); // DISPLAYS NULL [super viewDidLoad]; } Why isn't my variables available in viewdidLoad when I declared and implemented in my .h and .m files? If that's the case, is viewDidLoad or viewWillAppear the common places to load the data for the viewcontroller? It looks like even if you instantiate a viewcontroller, the init function gets called but the viewDidLoad doesn't necessarily have the variables to be displayed. Where's the right place/methods to load the model(data) for my viewcontroller? Thanks in advance

    Read the article

  • Here i m sending my code for presentmodelViewController

    - by aman-gupta
    Hi Please help me out i want to switch to first view from third view directly here is my code:-where i m using presentModelViewcontroller // // ExperimentAppDelegate.h // Experiment // // Created by Aman on 4/20/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import <UIKit/UIKit.h> @class ExperimentViewController; @class SecondView; @class ThirdView; BOOL parentScreenNo; @interface ExperimentAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; ExperimentViewController *viewController; SecondView *ptrSecond; ThirdView *ptrThird; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet ExperimentViewController *viewController; @property (nonatomic, retain) IBOutlet SecondView *ptrSecond; @property (nonatomic, retain) IBOutlet ThirdView *ptrThird; @end ///////////////////////////////////// // // ExperimentAppDelegate.m // Experiment // // Created by Aman on 4/20/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import "ExperimentAppDelegate.h" #import "ExperimentViewController.h" @implementation ExperimentAppDelegate @synthesize window; @synthesize viewController,ptrThird,ptrSecond; - (void)applicationDidFinishLaunching:(UIApplication *)application { parentScreenNo = NO; // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } @end ///////////////////////////////////////// // // ExperimentViewController.h // Experiment // // Created by Aman on 4/20/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import <UIKit/UIKit.h> @interface ExperimentViewController : UIViewController { } -(IBAction)second:(id)sender; @end /////////////////////////////// // // ExperimentViewController.m // Experiment // // Created by Aman on 4/20/10. // Copyright __MyCompanyName__ 2010. All rights reserved. // #import "ExperimentViewController.h" #import "ExperimentAppDelegate.h" @implementation ExperimentViewController /* // 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; } */ -(IBAction)second:(id)sender { ExperimentAppDelegate *app = (ExperimentAppDelegate *)[[UIApplication sharedApplication]delegate]; [self presentModalViewController:app.ptrSecond animated:YES]; } /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ /* // 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)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 ///////////////////////////////// // // SecondView.h // Experiment // // Created by Aman on 4/20/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> @interface SecondView : UIViewController { } -(IBAction)third:(id)sender; -(void)down; @end //////////////////////////////////////////// // // SecondView.m // Experiment // // Created by Aman on 4/20/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "SecondView.h" #import "ExperimentAppDelegate.h" @implementation SecondView /* // 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]; } -(void)viewWillAppear:(BOOL)animated { if(parentScreenNo == YES) { [self performSelector:@selector(down) withObject:nil]; } [super viewWillAppear:YES]; } -(IBAction)third:(id)sender { ExperimentAppDelegate *app = (ExperimentAppDelegate *)[[UIApplication sharedApplication]delegate]; [self presentModalViewController:app.ptrThird animated:YES]; } -(void)down { [self dismissModalViewControllerAnimated:YES]; } /* // 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 ////////////////////////////////// // // ThirdView.h // Experiment // // Created by Aman on 4/20/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> @interface ThirdView : UIViewController { } -(IBAction)back:(id)sender; @end ////////////////////////////////// // // ThirdView.m // Experiment // // Created by Aman on 4/20/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "ThirdView.h" #import "ExperimentAppDelegate.h" @implementation ThirdView /* // 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]; } */ -(IBAction)back:(id)sender { [self dismissModalViewControllerAnimated:YES]; parentScreenNo = YES; } /* // 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 Above is my code for calling other view please tell how i can call my first view by using dismismodelViewController from third screen Please help me out

    Read the article

  • How can I get a default value in some instances but not others?

    - by Connor Wagner
    I am making an iPhone app and want to use an 'if' statement and a boolean to set default values in some instances but not others... is this possible? Are there alternative options if it is not possible? In the MainViewController.m I have: @interface MainViewController (){ BOOL moveOver; } [...] - (void)viewDidLoad { [super viewDidLoad]; _label.text = [NSString stringWithFormat:@"%i", computerSpeed]; } } [...] - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller { [self dismissViewControllerAnimated:YES completion:nil]; moveOver = true; } The problem that it is redefined when the ViewDidLoad runs... I need a statement that will not redefine when the ViewDidLoad runs. I have something that I feel like is much closer to working... In the ViewDidLoad I have: if (playToInt != 10 || computerMoveSpeed != 3) { moveOver = TRUE; } which connects to my created method, gameLoop. It has if (moveOver == false) { computerMoveSpeed = 3; playToInt = 10; } I have tried putting the code in the gameLoop into the ViewDidLoad, but it had the same effect. When moveOver was false, the computerMoveSpeed and the playToInt were both seemingly 0. I have two UITextFields and typed 10 and 3 in them... does this not set it to the default? It seems to set the default to 0 for both, how do I change this? THIS IS A DIFFERENT ISSUE THAN THE THREE BOOLEAN VALUES QUESTION

    Read the article

  • Why is my app delegate's didFinishLaunchingWithOptions method all of sudden being called AFTER my Ro

    - by BeachRunnerJoe
    Hi. I've been playing with the iPad's SplitView template in Xcode. Here are two of the many important methods that are auto-generated for you by the Split View-based Application template... AppNameAppDelegate.m #pragma mark - #pragma mark Application lifecycle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after app launch rootViewController.managedObjectContext = self.managedObjectContext; // Add the split view controller's view to the window and display. [window addSubview:splitViewController.view]; [window makeKeyAndVisible]; return YES; } RootViewController.m #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.clearsSelectionOnViewWillAppear = NO; self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); NSError *error = nil; if (![[self fetchedResultsController] performFetch:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } When you build and run the project before making any changes at all, the application:didFinishLaunchingWithOptions method is called before the RootViewController:viewDidLoad method is called. I'm new to iPhone development, but I'm assuming this is the correct and typical sequence. However, as soon as I changed the RootViewController code and set it as a subclass of UIViewController (instead of UITableViewController by default), and made the respective adjustments in Interface Builder, suddenly the RootViewController:viewDidLoad is being called before the application:didFinishLaunchingWithOptions method. I need to get it back to the way it was working before because, as you can see in the code, the viewDidLoad method depends on didFinishLauchingWithOptions method to execute so it can set the rootViewController's managedObjectContext that it uses to perform the fetch request. Any ideas what caused this? Any ideas how I can fix this? Thanks so much in advance for your help! I'm gonna keep researching and playing with the code.

    Read the article

  • ViewController init?

    - by fuzzygoat
    I have just noticed that my ViewController does not call init (See below) when it starts up. -(id)init { self = [super init]; if(self) { NSLog(@"_init: %@", [self class]); otherStuff... } return self; } Is there a reason for this, or is it replaced by viewDidLoad -(void)viewDidLoad { otherStuff .. [super viewDidLoad]; } cheers gary

    Read the article

  • Why can't I initialize a class through a setter?

    - by Rob emenaker
    If I have a custom class called Tires: #import <Foundation/Foundation.h> @interface Tires : NSObject { @private NSString *brand; int size; } @property (nonatomic,copy) NSString *brand; @property int size; - (id)init; - (void)dealloc; @end ============================================= #import "Tires.h" @implementation Tires @synthesize brand, size; - (id)init { if (self = [super init]) { [self setBrand:[[NSString alloc] initWithString:@""]]; [self setSize:0]; } return self; } - (void)dealloc { [super dealloc]; [brand release]; } @end And I synthesize a setter and getter in my View Controller: #import <UIKit/UIKit.h> #import "Tires.h" @interface testViewController : UIViewController { Tires *frontLeft, *frontRight, *backleft, *backRight; } @property (nonatomic,copy) Tires *frontLeft, *frontRight, *backleft, *backRight; @end ==================================== #import "testViewController.h" @implementation testViewController @synthesize frontLeft, frontRight, backleft, backRight; - (void)viewDidLoad { [super viewDidLoad]; [self setFrontLeft:[[Tires alloc] init]]; } - (void)dealloc { [super dealloc]; } @end It dies after [self setFrontLeft:[[Tires alloc] init]] comes back. It compiles just fine and when I run the debugger it actually gets all the way through the init method on Tires, but once it comes back it just dies and the view never appears. However if I change the viewDidLoad method to: - (void)viewDidLoad { [super viewDidLoad]; frontLeft = [[Tires alloc] init]; } It works just fine. I could just ditch the setter and access the frontLeft variable directly, but I was under the impression I should use setters and getters as much as possible and logically it seems like the setFrontLeft method should work. This brings up an additional question that my coworkers keep asking in these regards (we are all new to Objective-C); why use a setter and getter at all if you are in the same class as those setters and getters.

    Read the article

  • Why are controls (null) in awakeFromNib?

    - by fuzzygoat
    This is a follow on from another question regarding why I could not set UIControls in awakeFromNib. The answer to that is that as you can see below the controls are nil in the awakeFromNib, although they are initialised to the correct objects by the time we get to viewDidLoad. I setup the view the same as I always do, should I be doing something different to access them here, the xib(nib) was designed and saved with the current version of Image Builder. CODE: @interface iPhone_TEST_AwakeFromNibViewController : UIViewController { UILabel *myLabel; UIImageView *myView; } @property(nonatomic, retain)IBOutlet UILabel *myLabel; @property(nonatomic, retain)IBOutlet UIImageView *myView; @end . @synthesize myLabel; @synthesize myView; -(void)awakeFromNib { NSLog(@"awakeFromNib ..."); NSLog(@"myLabel: %@", [myLabel class]); NSLog(@"myView : %@", [myView class]); //[myLabel setText:@"AWAKE"]; [super awakeFromNib]; } -(void)viewDidLoad { NSLog(@"viewDidLoad ..."); NSLog(@"myLabel: %@", [myLabel class]); NSLog(@"myView : %@", [myView class]); //[myLabel setText:@"VIEW"]; [super viewDidLoad]; } OUTPUT: awakeFromNib ... myLabel: (null) myView : (null) viewDidLoad ... myLabel: UILabel myLabel: UIImageView Much appreciated ... gary

    Read the article

  • Doing some downloading without blocking you app

    - by Code
    Hi guys, I'm working on my first app that's doing a few different web connections at once. My first screen is my Menu. And at the bottom of viewDidLoad of MenuViewController i call a method that gets and parses a .xml file that is located on my webserver. Also at the bottom of viewDidLoad i do FootballScores = [[FootBallScores alloc] init]; and FootballScores makes a connection to a html page which it loads into a string and then parses out data. Now since both of these are getting called at the bottom of viewDidLoad of the class thats is responsible for the main menu(first screen in the app) it means the app is kinda slow to load. What is the right way to do the above? Should i remove the 2 pieces of code from my viewDidLoad and replace with maybe dataGetterOne = [NSTimer scheduledTimerWithTimeInterval:1.000 target:self selector:@selector(xmlParser) userInfo:nil repeats:NO]; dataGetterTwo = [NSTimer scheduledTimerWithTimeInterval:2.000 target:self selector:@selector(htmlParser) userInfo:nil repeats:NO]; This would mean that the methods get called later on and the viewDidLoad gets to finish before the i try get the data from the web servers. Making 2 connections to we bservers a second apart to quick? Can the iphone handle having 2 connections open at once? I'm really unsure of anything bad/dangerous I am doing in regards to connections. Many Thanks -Code

    Read the article

  • delegate issues in Xcode

    - by trludt
    .h file #import <UIKit/UIKit.h> @interface AddEventViewController : UIViewController <UITextViewDelegate> @end .m file @property (weak, nonatomic) IBOutlet UITextField *textField1; @property (weak, nonatomic) IBOutlet UITextField *textField2; @property (weak, nonatomic) IBOutlet UITextField *textField3; - (IBAction)textFieldReturn:(id)sender; @end @implementation AddEventViewController @synthesize textField1, textField2, textField3; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (IBAction)textFieldReturn:(id)sender; { [sender resignFirstResponder]; } - (void)viewDidLoad { [super viewDidLoad]; self.textField1.delegate = self; textField1.delegate = self; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)touchesBegan: (NSSet *) touches withEvent: (UIEvent *)event { if (textField1) { if ([textField1 canResignFirstResponder]) [textField1 resignFirstResponder]; } [super touchesBegan: touches withEvent: event]; if (textField2) { if ([textField2 canResignFirstResponder]) [textField2 resignFirstResponder]; } [super touchesBegan: touches withEvent: event]; if (textField3) { if ([textField3 canResignFirstResponder]) [textField3 resignFirstResponder]; } [super touchesBegan: touches withEvent: event]; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField1 resignFirstResponder]; return NO; [textField2 resignFirstResponder]; return NO; [textField3 resignFirstResponder]; return NO; } @end Ok so im getting the yellow bug symbol on the lines: - (void)viewDidLoad { [super viewDidLoad]; self.textField1.delegate = self; textField1.delegate = self; } I don't know how to delegate all of my textFields? how do i make this textFieldReturn work for all of my textFields.. that viewDidLoad area has to be the problem, because everything else works good...

    Read the article

  • iPhone dev - viewDidUnload subviews

    - by Mk12
    I'm having a hard time undestand a couple of the methods in UIViewController, but first I'll say what I think they are meant for (ignoring interface builder because I'm not using it): -init: initialize non view-related stuff that won't need to be released in low memory situations (i.e. not objects or objects that can't be recreated easily). -loadView: create the view set the [self view] property. -viewDidLoad: Create all the other view elements -viewDidUnload: Release objects created in -viewDidLoad. didReceiveMemoryWarning: Low-memory situation, release unnecessary things such as cached data, if this view doesn't have a superview then the [super didReceiveMemoryWarning] will go on to release (unload) the view and call -viewDidUnload. -dealloc: release everything -viewWillAppear:, -viewDidAppear:, -viewWillDisappear:, -viewDidDisappear: self-explanatory, not necessary unless you want to respond (do something) to those events. I'm not sure about a couple of things. First, the Apple docs say that when -viewDidUnload is called, the view has already been released and set to nil. Will -loadView get called again to recreate the view later on? There's a few things I created in -viewDidLoad that I didn't make a ivar/property for because there is no need and it will be retained by the view (because they are subviews of it). So when the view is released, it will release those too, right? When the view is released, will it release all its subviews? Because all the objects I created in -viewDidLoad are subviews of [self view]. So if they already get released why release them again in -viewDidUnload? I can understand data that is necessary when the view is visible being loaded and unloaded in these methods, but like I asked, why release the subviews if they already get released? EDIT: After reading other questions, I think I might have got it (my 2nd question). In the situation where I just use a local variable, alloc it, make it a subview and release, it will have a retain count of 1 (from adding it as a subview), so when the view is released it is too. Now for the view elements with ivars pointing to them, I wasn't using properties because no outside class would need to access them. But now I think that that's wrong, because in this situation: // MyViewController.h @interface MyViewController : UIViewController { UILabel *myLabel; } // MyViewController.m . . . - (void)viewDidLoad { myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 10)]; [myLabel setText:@"Foobar"]; [[self view] addSubview:myLabel]; } - (void)viewDidUnload [ // equivalent of [self setMyLabel:nil]; without properties [myLabel release]; myLabel = nil; } In that situation, the label will be sent the -release message after it was deallocated because the ivar didn't retain it (because it wasn't a property). But with a property the retain count would be two: the view retaining it and the property. So then in -viewDidUnload it will get deallocated. So its best to just always use properties for these things, am I right? Or not? EDIT: I read somewhere that -viewDidLoad and -viewDidUnload are only for use with Interface Builder, that if you are doing everything programmatically you shouldn't use them. Is that right? Why?

    Read the article

  • popView from UITabBarController inside UINavigationController

    - by Manu
    Hi, I'm building an application based on the Utility template from Xcode, to which I have added some more views. My application structure would be as follows: MainView (the app menu) Flip-side view (a calculator) UINavigationController Settings view viewDiDLoad: UITabBarController - Tab1 view (options) - Tab2 view (information text) I can navigate correctly from my MainView to my Flip-side view, which is also the root view of the Navigation Controller. From my Flip-side view, I push a second view of my Navigation Controller (Settings view) that is configured to show an UITabBarController, with two tabs, as soon as it loads (with viewDidLoad). If I remove the UITabBarController, I can return with no problems to my Flip-side view using "popViewController" from my Settings view. The problem comes if I load the UITabBarController in viewDiDLoad in my Settings view... the tabs work perfectly, but I'm not able to return to my Flip-side view (root view of the Navigation Controller) anymore. I CAN return if I use the Navigation Bar of the Navigation Controller, but I want to configure my own buttons and have the Navigation Bar hidden. So far I've tried the following methods: [self.navigationController popViewControllerAnimated:YES]; [self.navigationController popToRootViewControllerAnimated:YES]; [self.navigationController popToViewController:FlipSideViewController animated:YES]; But they don't seem to work. The first two just do nothing (the screen remains as it was), and the third one does not recognize the "FlipsideViewController" (maybe because it's a delegate of the MainViewController?). Is there a way to check what is exactly doing the "back" button of the Navigation Bar if I activate it? Should I be using delegates? Can I call a popViewController method in my Settings view from any of the two Tab views? This is my Flip-side view: - (IBAction)showSettingsView { SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil]; controller.title = @"Settings"; [self.navigationController pushViewController:controller animated:YES]; [controller release]; } This is my Settings view: - (void)viewDidLoad { [super viewDidLoad]; tabBarController = [[UITabBarController alloc] init]; Tab1ViewController* vc1 = [[Tab1ViewController alloc] init]; Tab2ViewController* vc2 = [[Tab2ViewController alloc] init]; NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil]; tabBarController.viewControllers = controllers; [self.view addSubview:tabBarController.view]; } And the method to return in one of the Tab views: - (IBAction)backFromTab1View { [self.navigationController popToViewController:FlipSideViewController animated:YES]; } Thanks very much and sorry if the question is too basic!

    Read the article

  • Problem with Landscape and Portrait view in a TabBar Application

    - by JoshD
    I have an TabBar app that I would like to be in landscape and portrait. The issue is when I go to tab 2 make a selection from my table then select tab 1 and rotate the device, then select tab 2 again the content does not know that the device rotated and will not display my custom orientated content correctly. I am trying to write a priovate method that tells the view what orientation it is currently in. IN viewDidLoad I am assuming it is in portrait but in shouldAutoRotate I have it looking in the private method for the correct alignment of the content. Please Help!! Here is my code: #import "DetailViewController.h" #import "ScheduleTableViewController.h" #import "BrightcoveDemoAppDelegate.h" #import "Constants.h" @implementation DetailViewController @synthesize CurrentLevel, CurrentTitle, tableDataSource,logoName,showDescription,showDescriptionInfo,showTime, showTimeInfo, tableBG; - (void)layoutSubviews { showLogo.frame = CGRectMake(40, 20, 187, 101); showDescription.frame = CGRectMake(85, 140, 330, 65); showTime.frame = CGRectMake(130, 10, 149, 119); tableBG.frame = CGRectMake(0, 0, 480, 320); } /* // 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 { } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = CurrentTitle; [showDescription setEditable:NO]; //show the description showDescription.text = showDescriptionInfo; showTime.text = showTimeInfo; NSString *Path = [[NSBundle mainBundle] bundlePath]; NSString *ImagePath = [Path stringByAppendingPathComponent:logoName]; UIImage *tempImg = [[UIImage alloc] initWithContentsOfFile:ImagePath]; [showLogo setImage:tempImg]; [tempImg release]; [self masterView]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { isLandscape = UIInterfaceOrientationIsLandscape(toInterfaceOrientation); if(isLandscape = YES){ [self layoutSubviews]; } } - (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 { [logoName release]; [showLogo release]; [showDescription release]; [showDescriptionInfo release]; [super dealloc]; } @end

    Read the article

  • how to set objectForKey to UISwitch to access switch for save selected option

    - by Rkm
    SystemUIViewcontroller has button event. Tap on Button fire InfoTableviewController. InfoTableview has UISwitch. How to set objectForKey to Info to access UIswitch ViewDidload of System... - (void)viewDidLoad { [super viewDidLoad]; self.Infoarray = [NSMutableArray array]; Info *info = [[Info alloc]initWithNibName:@"Info" bundle:nil]; [self.Infoarray addObject:[NSDictionary dictionaryWithObjectsAndKeys:info, @"viewController", nil]]; } SystemUIviewcontroller button event... -(IBAction) Info_Button_Clicked:(id) sender { Info *info = [[Info alloc]initWithNibName:@"Info" bundle:[NSBundle mainBundle]]; [self.navigationController pushViewController:info animated:YES]; [info release]; } Here for Info TableviewController... - (void)viewDidLoad { [super viewDidLoad]; self.Soundarray = [NSArray arrayWithObjects: [NSDictionary dictionaryWithObjectsAndKeys: @"Sounds", @"labelKey", self.SoundsswitchCtl, @"viewKey", nil],nil]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; if ([indexPath section] == 0) { static NSString *kDisplayCell_ID = @"DisplayCellID"; cell = [self.tableView dequeueReusableCellWithIdentifier: kDisplayCell_ID]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: kDisplayCell_ID] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } else { // the cell is being recycled, remove old embedded controls UIView *viewToRemove = nil; viewToRemove = [cell.contentView viewWithTag:1]; if (viewToRemove) [viewToRemove removeFromSuperview]; } cell.textLabel.text = [[self.Soundarray objectAtIndex: indexPath.row] valueForKey:@"labelKey"]; UIControl *control = [[self.Soundarray objectAtIndex: indexPath.row] valueForKey:@"viewKey"]; [cell.contentView addSubview:control]; return cell; } } - (UISwitch *)SoundsswitchCtl { if (SoundsswitchCtl == nil) { CGRect frame = CGRectMake(198.0, 12.0, 94.0, 27.0); SoundsswitchCtl = [[UISwitch alloc] initWithFrame:frame]; [SoundsswitchCtl addTarget:self action:@selector(switch_Sounds:) forControlEvents:UIControlEventValueChanged]; // in case the parent view draws with a custom color or gradient, use a transparent color SoundsswitchCtl.backgroundColor = [UIColor clearColor]; [SoundsswitchCtl setAccessibilityLabel:NSLocalizedString(@"StandardSwitch", @"")]; SoundsswitchCtl.tag = 1; // tag this view for later so we can remove it from recycled table cells } return SoundsswitchCtl; }

    Read the article

  • How load WebView with another URL when navigated through tab bar viewController

    - by TechFusion
    Hello, I have created window based application, root controller as Tab bar controller. WebView is being loaded in Tab bar interfaced ViewController's View.WebView is created using IB.WebView object declared in ViewController as per below. //ViewController.h @interface ViewController:UIViewController{ IBOutlet UIWebview *Webview; } @property(nonatomic,retain)IBOutlet UIWebview *Webview; @end I am calling [WebView loadrequest] method in -viewDidLoad method and stopLoading will be called in -viewWillDisappear method. I am again reload it in -viewWillAppear:animated method to load it again when tab bar is pressed. //ViewController.m @implementation viewcontroller @synthesize Webview; -(void)viewDidLoad{ [super viewDidLoad]; [self.Webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"www.apple.com"]]]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.Webview reload]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.Webview stopLoading]; } I am releasing WebView in -ViewDidUnload method -(void)viewDidUnload{ [super viewDidUnload]; [Webview release]; } -(void)dealloc{ [Webview release]; [super dealloc]; } Does Webview released correctly ? Here how to kill connection with URL when ViewWillDisappear method called ? How to load View with Different URL then it's loaded in -viewDidLoad method when ViewController interfaced tab is pressed ? Means if naviagated from one tab to another that ViewController interface tab which has WebView should load request with another URL. Does it correct to call [self.Webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"www.stackoverflow.com"]]]; this method again in -viewWillAppear:animated method to load with another URL ? Thanks,

    Read the article

  • UIWebView not loading URL when URL is passed from UITableView

    - by Mark Hazlett
    Hey Everyone, So i'm building a webView into my application to show the contents of a URL that I am passing from a selection in a UITableView. I know the UIWebView is loading content properly because if you hard code say http://www.google.ca into the NSURL then it loads fine, however when I'm passing the URL that I parsed from an RSS feed back from the UITableView it won't load the URL properly. I tried the debugger and the URL is coming out as nil right before I try and parse it, however I can use NSLog to print the value of it out to the console. here's the code in my UIViewController that has my UIWebView #import <UIKit/UIKit.h> @interface ReadFeedWebViewController : UIViewController { NSString *urlToGet; IBOutlet UIWebView *webView; } @property(nonatomic, retain) IBOutlet UIWebView *webView; @property(nonatomic, retain) NSString *urlToGet; @end Here's the code for my implementation's viewDidLoad method... // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"Url inside Web View Controller - %@", urlToGet); NSURL *url = [NSURL URLWithString:urlToGet]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [self.webView loadRequest:requestObj]; } Once again, I can print the URL to NSLog fine and if I hard code the URL into the NSURL object then it will load fine in the UIWebView. Here is where I'm setting the value in my UITableViewController... - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ReadFeedWebViewController *extendedView = [[ReadFeedWebViewController alloc] init]; int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; extendedView.urlToGet = [[stories objectAtIndex: storyIndex] objectForKey:@"link"]; //NSLog([[stories objectAtIndex: storyIndex] objectForKey:@"summary"]); NSLog([[stories objectAtIndex: storyIndex] objectForKey:@"link"]); [self.navigationController pushViewController:extendedView animated:YES]; [extendedView release]; } However, since I can print the value using NSLog in the extendedView view controller I know it's being passed properly. Cheers

    Read the article

  • iPhone SDK - UITabBarConroller and custom design

    - by Cheryl
    Hi I am having a problem with my tab bars at the bottom of the screen. The designer has decided it should be one colour (not black) when inactive and another colour when active. I have worked out how to replace the main colour of the tabbar by subclassing UITabBarController and doing this:- - (void)viewDidLoad { [super viewDidLoad]; CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, self.view.bounds.size.height); UIView *v = [[UIView alloc] initWithFrame:frame]; //get percentage values from digitalcolour meter and enter as decimals v.backgroundColor = [UIColor colorWithRed:.0 green:.706 blue:.863 alpha:1]; [tabBar1 insertSubview:v atIndex:0]; [v release]; } I just can't see how to make the active tabbar be a separate colour when it is selected. I have tried subclassing UITabBarItem but there doesn't seem to be any property for me to set to change the background colour of the tab. They also want to have the icons on the tab bar not be blue and grey and I can't figure out how to do that. In the ViewController for one tab bar item I have put this into viewdidload:- myTabBarItem *tabItem = [[myTabBarItem alloc] initWithTitle:@"listOOO" image:[UIImage imageNamed:@"starcopy.png"] tag:1]; tabItem.customHighlightedImage=[UIImage imageNamed:@"starcopy.png"]; self.tabBarItem=tabItem; [tabItem release]; tabItem=nil; and in my subclass of UITabBarItem I have put this:- -(UIImage *) selectedImage{ return self.customHighlightedImage; } Only I don't see the icon at all. If I put this into the viewDidLoad of my subclass of UITabBarController:- for (UITabBarItem *item in tabBar1.items){ item.image = [UIImage imageNamed:@"starcopy.png"]; } Then all my tab bars have the icon but they are blue (and grey when inactive) how would I get them not to become blue but stay their original colour? If you have any light on this problem please help as I have been banking my head on the wall for 2 days now and it's getting me down. Thanks in advance Cheryl

    Read the article

  • NSMutableArray to NSString and Passing NSString to Another View IOS5.1

    - by Space Dust
    I have an NSMutableArray of names. I want the pass the data (selected name) inside of NSMutableArray as text to another view's label. FriendsController.m: - (void)viewDidLoad { [super viewDidLoad]; arrayOfNames=[[NSMutableArray alloc] init]; arrayOfIDs=[[NSMutableArray alloc] init]; userName=[[NSString alloc] init]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { long long fbid = [[arrayOfIDs objectAtIndex:indexPath.row]longLongValue]; NSString *user=[NSString stringWithFormat:@"%llu/picture",fbid]; [facebook requestWithGraphPath:user andDelegate:self]; userName=[NSString stringWithFormat:@"%@",[arrayOfNames objectAtIndex:indexPath.row]]; FriendDetail *profileDetailName = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil]; profileDetailName.nameString=userName; [profileDetailName release]; } - (void)request:(FBRequest *)request didLoad:(id)result { if ([result isKindOfClass:[NSData class]]) { transferImage = [[UIImage alloc] initWithData: result]; FriendDetail *profileDetailPicture = [[FriendDetail alloc] initWithNibName: @"FriendDetail" bundle: nil]; [profileDetailPicture view]; profileDetailPicture.profileImage.image= transferImage; profileDetailPicture.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:profileDetailPicture animated:YES]; [profileDetailPicture release]; } } In FriendDetail.h NSString nameString; IBOutlet UILabel *profileName; @property (nonatomic, retain) UILabel *profileName; @property (nonatomic, retain) NSString *nameString; In FriendDetail.m - (void)viewDidLoad { [super viewDidLoad]; profileName.text=nameString; } nameString in second controller(FriendDetail) returns nil. When i set a breakpoint in firstcontroller I see the string inside of nameString is correct but after that it returns to nil somehow.

    Read the article

  • UIWebview does not show up into UINavigationController

    - by Pato
    Hi I have a tabBar application. In the first tab, I have a navigation bar. In this navigation bar I have a table view. When the user clicks a cell of the table, it goes to another table view, and when the user clicks a cell in that table, it goes to a webview to open a web page. Basically, it goes fine until opening the webview. In the webview, viewDidLoad is called and seems to work properly. However, webViewDidStartLoad is never called and the web page never shows up. I am not using IB. I build the UITabBarController in the AppDelegate, where I also assign an instance of my UINavigationController for each tab. I call the webview from the second UITableViewController as follows: rssWebViewController = [[webViews objectAtIndex: indexPath.row] objectForKey:@"controller"]; [[self navigationController] pushViewController:rssWebViewController animated:YES]; I have checked that the navigationController is there and it seems just fine. The viewDidload of my webview is as follows: - (void)viewDidLoad { [super viewDidLoad]; NSString *urlAddress = self.storyUrl; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [[self rssWebView] setDelegate: self]; [[self view] addSubview:[self rssWebView]]; [rssWebView loadRequest:requestObj]; self.rssWebView.scalesPageToFit = YES; self.rssWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); } The web view controller interface is defined as follows: @interface RSSWebViewController : UIViewController <UIWebViewDelegate>{ IBOutlet UIWebView *rssWebView; IBOutlet NSString *storyUrl; IBOutlet NSString *feedName; } @property (nonatomic, retain) IBOutlet UIWebView *rssWebView; @property (nonatomic, retain) IBOutlet NSString *storyUrl; @property (nonatomic, retain) IBOutlet NSString *feedName; @end Any help is greatly appreciated.

    Read the article

  • UIImageView subclass with CGRectIntersectsRect - help!

    - by Flafla2
    The title of this question should be pretty self explanatory. I am making an app that involves multiple UIImageViews that serve the same purpose. They are merely different sizes. Anyway, I decided that the best solution was to make UIImageView subclasses, link the subcalsses in IB, and work from there. My code should explain this better - #define kPausedStatePaused 1 #define kPausedStatePlay 2 #import "Game.h" #import "ScoreSystem.h" @interface Doctor : UIImageView { } @end @interface Ground : UIImageView { } @end @interface Wall : UIImageView { } @end @interface Electric_Wire : UIImageView { } @end @implementation Game /* // 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]; } */ - (IBAction)pause { UIAlertView *pause = [[UIAlertView alloc] initWithTitle:@"Pause" message:nil delegate:self cancelButtonTitle:@"Quit" otherButtonTitles:@"Play", nil]; [pause show]; [pause release]; pauseint = kPausedStatePaused; } - (void)viewDidAppear { pauseint = kPausedStatePlay; } - (void)loop { Doctor *doctorview; Ground *groundview; if (CGRectIntersectsRect(doctorview, groundview)) { } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if ([alertView.title isEqual:@"Pause"]) { if(buttonIndex == 0) [self dismissModalViewControllerAnimated:YES]; pauseint = kPausedStatePlay; } } // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } - (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 Unsurprisingly, Xcode gave me an "incompatible type for CGRectIntersectsRect" error.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >