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?
Related
I have view control with five button i am setting there properties also is it necessary to release them in dealloc thanks
#interface MainViewController : UIViewController{
IBOutlet UIButton*homeButton;
IBOutlet UIButton*economicDataButton;
IBOutlet UIButton*riskButton;
IBOutlet UIButton*financialImpactButton;
IBOutlet UIButton*probabilitiesButton;
IBOutlet UIButton*enterButton;
}
in ARC you don't have to. the system does it for you. but if you are not using arc then you may do it. even when i use arc or partial arc just for a few classes i still do it. i guess i'm a paranoid coder.:)
EDIT:
well if it is your project and you started it then you must check the box at the beginning for using automatic reference counting or not checking it. if you are using a sample project from someone else then go the target level of your project. then you go to built phases and expand that and see if this phrase is in front of anyone of them. -fobjc-arc. that is for the projects that started without arc and then arc was added to some classes. on the hand if the entire project is arc enabled just declare a iboutlet and try to synthesis it and project will give you an error asking for storng or weak reference. that's how you know that entire project is arc enabled.
happy coding my friend
I'm noticing something really strange.
I have a class A with a property:
#interface ClassA
#property (nonatomic, strong) NSString *test;
and a synthesize in the .m file.
now if I have a second class B as following:
#import "ClassA.h"
-(void) someMethod
{
ClassA *classA = [[ClassA alloc] init];
classA.test = #"test";
}
than this works fine if the 2 class files are in the same folder.
If I however move the files to separate subfolders, it won't work anymore.
The error I get is that the property doesn't exist. Similarly, 'intellisense' won't show the test property anymore.
If I make folder groups in xcode, but leave the actual files in the same physical folder, it does work.
Whats going on here?
It can't be an include path problem, since then I wouldn't even be able to instantiate ClassA.
already tried Xcode menu "product:clean"?
and i would try to delete your app from simulator, and also Xcode:preferences:locations:derived data -> from finder delete that finder folder
Try COMMAND+SHIFT+K and
Reset content and settings in iOS Simulator.
Did you try #class ClassA?
I solved it. I had an included subproject which used a class with the exact same name.
aaaaargh...
apparently there are no errors during compilation and it's unclear which of the files it will import.
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.
I have been developing for iPhone from last 1-2 months and all the time for taking IBOutlet I use the following method to declare any property:
In .h files:
#interface ....
{
controlType varName;
}
#property() IBOutlet controlType varName;
In .m files:
at top -#synthesize varName;
in delloc method - [varName release];
Although the method is good but it isn't very good when its taking a couple of minutes just for declaring property.
Is there any automatic process for declaring properties, IBOutlets, IBActions or basic data variables.
I hope there should be some automatic methods for this scenario as this is a very basic process.
Thanks all.
Another one that not many people are aware of is that you can drag from Interface Builder to your header file to create IBActions or IBOutlets.
NOTE: Open the Assistant Editor with focus on the XIB inside IB.
If you create your IBOutlets this way Xcode automatically adds the property, synthesizes it, sets it to nil in viewDidUnload and releases it in dealloc.
You simply drag from the IB object to your header file the same way you would when creating connections between the view objects and their file owners (screenshot below).
In fact, yes!
You no longer need to declare the actual iVar.
In short, simply leave out this part: controlType varName;
For now, you do still need to explicitly "synthesize".
(As far as I can see, they could possibly automate that in the future. But for now you have to "synthesize" to create the setter and getter.)
You do still have to release the memory - there's really no way that could be automated, as memory handling is "real he-man programming."
For any new chums reading, don't forget the "self." part when using the property.
Plus note that XCode4 even has a new automatic thingy. Simply drag from the interface builder, to your .h file, and it will do everything for you -- try it!
In answer to your suplementary question: An IBOutlet DOES NOT PARTICULARLY NEED TO BE a property - you can just use a normal cheap iVar. On the other hand, if you wish, to you can use a property. Furthermore: you can even use the new trick (2011) of not bothering to declare the ivar, just use the property declaration, and shove an IBOutlet in there!
There is an awesome tool that speeds the whole process up: accessorizer.
You write controlType varName; select it and press some buttons and accessorizer will create the property, init, dealloc, viewDidUnload and much more for you. You just have to paste the code into your project.
Try it, a demo is available.
You can save yourself having to release the object by changing the property declaration. If you use:
#property (assign) IBOutlet controlType varName;
retain wont be called on your view so you wont have to release it later. This is generally safe as views are retained when they are added to a parent. If you are removing the views from their parent for some reason then you will have to retain them.
Here's an xcode script to automate the tedium of declaring properties.
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"