This question already has answers here:
Difference between viewDidLoad and viewDidAppear
(2 answers)
Closed 5 years ago.
Bottom line is, I've been working on an app, and it seems that if I place a UIAlert in viewDidLoad, it gets called twice (from a delegate method of UIImagePickerController). If I put it in viewDidAppear, it gets called once.
I've looked through documentation but it just confuses me.
A UIView object can get loaded into memory and released multiple times without ever getting added to the view stack and appearing on the display.
My guess is that you have 2 references to this view (maybe one in a nib file?), so it's getting loaded, then released when the second reference is loaded and assigned to the same property, then only the latter gets added to the view stack. You can see this by printing out (NSLog) the integer value of self ("%ld",(long int)self) in the viewDidLoad and viewDidAppear methods.
Related
This question already has answers here:
What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?
(16 answers)
Closed 2 years ago.
I'm new to Xcode and was trying to make a simple code that would unhide a label when a button is pressed. I tried using the same code in a test project with one view controller and it worked just fine, but when I use it in a bigger project with 15+ view controllers I get the error. My outlets seem to be correct so I am not sure what is making the label nil.
Code that I used
Fixed it! Just manually initialized the object as hidden under drawing.
This error seem to be caused by the Outlet connecting problem to me,
I would suggest you to double check the storyboard & viewController connection.
To do so, you can go to your storyboard, and check on the all outlet connector in that scene.
If there are yellow sign, that mean that are the problems.
enter image description here
But if the outlet are correctly connect, try to move that line of code to ViewWillAppear, and see if the error still occurs.
First of all, I am not Objective-c developer, however I have 4 years of experience in C and C++.
I am trying to make a few demo programs for an (iPad) app camp. For one of these programs I want to pass data between two UIViewControllers.
I have tried various examples, among the example below.
Passing Data between View Controllers
The code is written in an older version of Xcode so I took a bit of tweaking to get it through the compiler. Now I am facing the following problems:
It seems the prepareForSegue is not being called when I open a new view? (Or am I doing something wrong?) I have tried various ways.
In the same post there is a way to pass a delegate to a new class and back to the calling class. When I run this all goes good but there is the last part:
In ViewControllerA.m implement the following method from our protocol
(void)addItemViewController:(ViewControllerB *)controller didFinishEnteringItem:(NSString *)item
{
NSLog(#"This was returned from ViewControllerB %#",item);
}
Does net execute... I have no idea what is wrong. I followed the example exactly. I can see the second view opening and closing, only the delegate code won't run. Do I have to do this in a different way in Xcode 7?
P.S. I know this is a basic question but I cant seem to find the answer or a good Xcode 7 guide anywhere.
following method from our protocol.. Does net execute...
Are you sure that you assign your first view controller's reference to your target view controller's delegate property like,
secondViewController.delegate = self;
You can do this in where you create the second view controller, e.g prepareForSegue method. If you forgot this your delegate method simply not work, because your second view controller doesn't know who's its delegate.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I created a navigation controller and put 2 view controllers linked to it. One is called FirstLaunchVC and the other is FirstLaunchVC2, I want the user to put his name in the text field nameTxtField and when he clicks on the continueBtn it should lead to the other. In this second view (FirstLaunchVC2) there is a label called nameGreetings which will show the name of the user as a greeting with prepareForSegue, the thing is that it's crashing, saying that there are breakpoints on the line of the performSegueWithIdentifier and on the line where I write "nextVC.nameGreetings.text = "(str) etc etc". I have no clue why, can anyone help me with that? Btw, I've already checked the identifier and it's correct.
Is nameGreetings an IBOutlet? You cannot set the IBOutlet controls for the destination view controller in prepareForSegue of the originating view controller because while the destination view controller has been instantiated, its views and IBOutlet references have not. The prepareForSegue should feel free to update String properties of the destination, but not its IBOutlet references.
So updating of name is fine, but the nameGreetings should not be set in prepareForSegue, but rather that should be deferred until the the viewDidLoad of that FirstLaunchVC2.
After having spent the whole day looking for a solution I feel only more confused and upset.
Let's face the problem:
I'm developing a single view iOS app made up of an AppDelegate (of course..), A ViewController and a "DrawingClass" (subclass of UIView).
In the main.storyboard i can see my mainViewControllerScene, and inside this main view directed by the viewController, I have inserted a UIView object from the palette in the interface builder and set it to be controlled by my "Drawing class" because I need to use the DrawRect method to draw custom lines.
Well, when starting the app, the defaults lines in my "DrawingClass" are being drawn, so drawrect is being called.
But when, after having pressed a button linked to an IBAction, I try
to call again drawrect through setNeedsDisplay or anything it doesn't
work.
Let's be more clear:
-I'm sure that the view controlled by "DrawingClass" is being drawn correctly on startup
-I'm sure that the IBAction is called (I used an NSLog)
-I can't figure out how to redraw that view. (The one controlled by "DrawingClass")
In the viewController I tried both [self.view setNeedsDisplay] and [myView setNeedDisplay] but none of them called my drawrect method in the "DrawingClass"
What I'm doing wrong? Am I forgetting to init something ? I tried even to call those methods on the main thread but nothing.
I think this question could help many so please ask if you need something more to work out this problem.
Thank you so much.
I have an Application, which is a SplitViewController that has a master view on the left and the detail view on the right. One of the views (Branch Finder) is a Map view that loads a series of Annotations to the Map.
If I let the annotations load before switching to any other view (loading the annotations take takes all of 1 second) then everything is fine. However, if the user quickly switches off the Branch Finder view, whilst the annotations are being loaded, then the App will crash with the following notice:
[BranchFinder_iPad respondsToSelector:]: message sent to deallocated instance 0x807d230
Now, my thoughts are that the deallocated instance would refer to the Array (declared in the header of the view) that contains all the annotations being released and set to nil when the user leaves the BranchFinder_iPad view. This is the array that is being passed to the addAnnotations method.
[self.mapView addAnnotations:branchSites];
Has anyone else encountered an issue where leaving a view, mid-way in the add allocations and a crash occurs if the user moves to another view.
Just to clarify:
If I wait for the annotations to load, switching to any other view causes no problem.
I did have a custom annotation view, but I stripped that out of my code (to eliminate it from the mix). Doing this has not changed anything.
I have looked elsewhere for help on this issue, but a lot of the view tutorials regarding map views are single view only, so this issue hasn't arisen.
I have found a vaguely similar issue # the following: mapkit addAnnotations crashes
And finally, I have just made the jump to x-code 4. I think some of my problems are just because I'm relearning some of the things I should know.
Regards,
Nathan A
PS: I wanted to attach an image to this, but am having trouble. I don't have the reputation points to do it natively, and my workplace doesn't allow me access to any image hosting portals. I will endeavour to add an image later today.
Hey anyone who reads this.
I basically performed a rookie mistake here - for the MKMapView in my application, I had to set the delegate to nil as part of the deallocation routine within my view. THe apple documentation makes mention of this in the below document:
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html
For the relevant section:
Before releasing an MKMapView object for which you have set a delegate, remember to set that object’s delegate property to nil. One place you can do this is in the dealloc method where you dispose of the map view.
Not having this was only causing an issue if I switched to another view AND if the MKMapView was still being referenced in executing code, such as the addAnnotations routine.