iPhone : Simple UITableViewController crash without console error nor debugging clue - iphone

I'm trying to build a simple TableView program struture.
It seems to work fine, but if I scroll the list to high or to low, the app crashes without any console error and the trace into the debugger does not help.
You can see it by yourself looking at the project I put at : http://shine.free.fr/tmp/myTestApp.zip
Can you help me :
to know what goes wrong
to know how I may find what goes wrong without having to ask each time. Usually I check my connection, lokk for compile errors, look into the console and try to debug, but there, nothing helps me.
Thank you for your help

The problem is that your ListController object is not retained when it is loaded from nib file, so it is not guaranteed that it will be valid after nib is loaded (and in fact it is not). To solve your problem add an outlet for ListController property and define retaining property for it. Here's FenetreListeController.h that fixes your problem:
#import <UIKit/UIKit.h>
#class ListeController;
#interface FenetreListeController : UIViewController {
IBOutlet ListeController* listController;
}
#property (nonatomic, retain) ListeController* listController;
#end
You will also need to set outlet connection in IB and synthesize property in .m file
For more information about how objects are loaded from xib files check "The Nib Object Life Cycle" section from "Resource Programming Guide"

Related

My objects in storyboard don't link correctly with the code

I am trying to use storyboards in my application. I began well, I have added two view controllers with a button to go from the first to the second.
The problem is in this second view controller: the objects I add on it and link with the code do not work. When I set a breakpoint in the view controller code, the 'self.property' is set to nil, whereas it should be instantiated by the storyboard.
I have been looking for an answer for hours, and I really don't understand the problem, since all the rest seems to be good.
I have tried to write the property in the code (strong/nonatomic, nonatomic/retain and even weak/nonatomic), to link the object directly to the code so that it creates the property automatically, but I never get anything else than "nil" with breakpoints.
viewController.h:
#interface NMLoadingViewController : UIViewController
{
__weak IBOutlet UIProgressView *imageProcessingProgressView;
}
#property (weak, nonatomic) IBOutlet UIProgressView *imageProcessingProgressView;
#end
.m:
#synthesize imageProcessingProgressView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Custom initialization
NSLog(#"INIT.");
}
(amont other lines of irrelevant code)
If I set the breakpoint to the "INIT." line, my imageProcessingProgressView is nil. I can't see a reason for that, I guess I have missed a very little detail...
(Note that I have tried this with other objects, like a UILabel, but it did not work either. Stranger, when I had two objects, one of them had an adress which was not nil, but still it was corrupted and did not show the right object.)
Edit: It was a lot of trouble for nothing... The problem is about the Variable View in XCode, which show my variable to "nil", whereas a log shows me a correct object...
Remove this...
{
__weak IBOutlet UIProgressView *imageProcessingProgressView;
}
...and make the property strong.
Change your log message to...
NSLog(#"INIT: %#", self.imageProcessingProgressView);
...and see if you still have a problem. If you do, then take another look at your storyboard connections.
Make sure NMLoadingViewController is the class on your viewController
First try out the answer by #Eric because I do believe that is the real issue.
Also, make sure that you are actually using the interface builder to hook the controls back to the view controller. This is done by dragging a line from the control back to the property of the view controller.

IBOutlet not connecting in Interface Builder- Xcode 4.2

I have read other questions here, but they seem to be for Xcode 3.2 or earlier, but nothing for 4.2. :(
I started a simple project and was wanting to connect the File Owner's Outlets within my xib. The bummer is that my IBOutlet's from my ViewController.h aren't coming over.
I don't have a reputation of 10 or above, so here is a screenshot of my File's Owner not showing my IBOutlets.
Here is my ViewController.h code:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UITextField *txtName;
IBOutlet UILabel *lblMessage;
}
#property (nonatomic, retain) IBOutlet UITextField *txtName;
#property (nonatomic, retain) IBOutlet UILabel *lblMessage;
- (IBAction)doSomething;
#end
Here is my ViewController.m code:
#import "ViewController.h"
#implementation ViewController
#synthesize txtName;
#synthesize lblMessage;
- (IBAction) doSomething
{
NSString *msg = [[NSString alloc] initWithFormat:#"Hello, %#",txtName.text];
[lblMessage setText:msg];
}
#end
I am new to Objective-C and Xcode, so I could have made a mistake, but I've followed many tutorials and I can never get my IBOutlets to show. I have gone as far as to delete Xcode 4.2 and re-installed to try and fix this issue. Here is a screenshot of my Xcode Version 4.2, Build 4D199 info.
Anyone else run into this issue? Thanks anyone who can point out any mistakes I have made. Please let me know if more information is needed.
When you create your IBAction, in the .h file, there will be a connection indicator to the left of it. When it isn't connected it shows a empty circle.
Press and hold this and drag it to the item you want to connect it to. I usually open up the XIB in a new window by double clicking it.
If it wont connect you must set the File's Owner in the XIB file. Select File's Owner in the Placeholders panel. Move over to the Utilities panel and make sure the Custom class, in Identity Inspector, is set to what ever your viewcontroller is named.
I Hope this will help you.
Cheers!
Try to reassign your file owner class reference in xib file.
Then attach all your IBOutlet connections.
Hope this might be helpful to you.
Check if the Files Owner is set to "ViewController". Check the following link:
http://developer.apple.com/library/ios/#documentation/IDEs/Conceptual/Xcode4TransitionGuide/InterfaceBuilder/InterfaceBuilder.html
Two things need to be added, before Xcode will allow creation of IBOutlet for the text field from the Storyboard:
Assign the underlying ViewController as the delegate to the UITextField
Add the to the #interface declaration in the ViewController.h file:
#interface ViewController : UIViewController<UITextFieldDelegate>
Until both of these are completed, you can Ctrl-click and drag from the Storyboard to the .h file, but no IBOutlet connection will be enabled.
I've finally figured out the issue, hope this helps anyone else currently having the same problem.
It had nothing to do with the xib's file owner setting. What my issue was that I had the xib file in a different directory than the source files, thus it wasn't able to connect the outlets. Once I moved the files to the same directory, everything worked. FYI, I moved everything to the top directory. Not sure sub directories will work...
To move the files, be sure to update xcode to point to the new locations.

Red underline that I cant figure out how to fix

I'm brand new to iPhone programming. I've tried some tutorials and such and now I'm trying to do a simple project to get my feet wet. And of course I have having issues getting it to do what I want. I started it by using a Navigation project. I didn't want the UITableView though I just want normal buttons that lead to the next page. Although when I tried to get rid of the UITableView I think I did it wrong so now it isn't working when I am setting up the next view.
Here is the .h (the red underline is under the MPHViewController in both places) Oh and what it wants to do is make both those UIViewController.
#import <UIKit/UIKit.h>
#import "MPHViewController.h"
#interface RootViewController : UIViewController {
MPHViewController *mphViewController;
}
#property(nonatomic,retain) MPHViewController *mphViewController;
#end
I'm thinking where I mainly messed up was in the .m (I think) I took out all the code that had to do with the UITableView and simply put this in (wasn't sure what else should be placed there).
- (UIViewController *)viewControl:(UIView *)view
{
}
Sorry for being a pain I just don't know any better way of learning how to do this other then just trial and error.
It might not be able to find the definition for your custom class.
In xcode under the project setting -> build phases, make sure the MPHViewController.m is included in the list of source files to be compiled.
Also, make sure in your MPHViewController.h that your subclassing UIViewController properly:
#interface MPHViewController : UIViewController
{
// ....
}
Make sure you synthesize it in the .m
#synthesize mphViewController;

Connecting an IBOutlet to a view within a scrollview within a tab view crashes app. Any ideas?

I used the tabview setup to create an app that has several tabs. One tab has a UIScrollView on it which loads 12 different views into 12 pages. I tried adding a button and imageview to one of the views and now it crashes. I've pored over every single question on here I can find, and have tried every suggested solution, but to no avail. The error that I get is the famous "this class is not key value coding-compliant for the key foo" error. As with everyone else who had this problem, if I disconnect the outlet, it works fine. I've checked and rechecked the class for the nib and it points to the right place.
So I'm not even sure where to go next.
I could post some code, but I don't even know what code would be helpful to post. I'm hoping someone just says, "Um yeah, you can't have a scroll view with multiple views in it and expect to have functionality on each page." That would be helpful!
Page2.h:
#import <UIKit/UIKit.h>
#interface Page2 : UIViewController {
IBOutlet UIImageView *infoImage;
}
#property (retain, nonatomic) UIImageView *infoImage;
(IBAction) showInfo:(id)sender;
#end
Page2.m:
- (IBAction)showInfo:(id)sender {
// do something please!
}
Then in the nib file I CTRL-dragged from "touch-up inside" on my button to the Files Owner and chose "showInfo" ... and I CTRL-dragged from Files Owner down to my UIImageView and chose infoImage.
CRASH
I am not cool enough to insert an image: http://i.stack.imgur.com/KjWhk.png
You still have an outlet connected in your nib that you no longer have defined in your class. You'll see in the inspector that it has turned gray. Disconnect it, and the error should be gone.
are u able to create any other outlet in the same Nib file, as i used to get the same crash, and it got fixed only when i duplicated the same nib, i had implemented almost all methods to solve it. If i am not wrong , this link can help you out https://discussions.apple.com/thread/2431110?start=0&tstart=0
I have sent you the email and attached your project. Hope its working at your end now.
Happy Coding!

iphone 'No declaration of property 'doSomethingButton' found in the interface' error

I am really confused - I am implementing a change to a button in several views and it works in all but 1 of them and I can't figure out what is different.
I have it declared in the .h file :
UIButton *doSomethingButton;
}
#property (nonatomic, retain) IBOutlet UIButton *doSomethingButton;
But then in the .m file I get the error 'No declaration of property 'doSomethingButton' found in the interface' in the #synthesize line and then again on the lines where it is actually used. I made sure the .m file imports the .h file. I made sure that the outlet is used correctly in Interface Builder. What else could be causing the problem?
For future reference:
I just had this happen to me. It turned out, the header (.h) file was not actually included in the project.
The tricky part is, Xcode still let me jump between counterparts and edit the file as normal, but when I tried to reveal the file in the group tree, it wasn't there.
Dragging the file back into the project from the Finder fixed the problem.
Are you sure you are doing the following in your .m file (ensure this is inside the implementation block):
#sythensize doSomethingButton
Odd; check very carefully for misspellings. I've also been occasionally burned by invisible characters ending up in the source.
Do other #property declarations work in the same pair of files?