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.
Related
Okay. So I have 3 .h and .m files, (2 controllers and 1 delegate) and I am somewhat new to Objective C so the instructions in dropbox have been confusing to say the least. I am coming from a Javascript background and understand the logic, but not what code to use. I tried putting the code in each combination of .h and .m files. (The controller .h and .m file then the .h and .m file for the delegate then the .h and .m file for the other controller deleting the code from the previous file before trying it on another set of files)
I am deeply confused and
.h file
#interface <controller/delegate> : NSObject {
DBRestClient *restClient;
}
.m file
- (DBRestClient*)restClient {
if (restClient == nil) {
restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
restClient.delegate = self;
}
return restClient;
}
I can only run this code in one of the classes. A controller, but I get this error:
Incompatible pointer types assigning to id
How would I fix this and is it even in the right place?
I am posting the link of dropbox Tutorial, in which you will find dropbox api and one tutorial project.It is very nicely described there.
https://www.dropbox.com/developers/reference/sdk
Below is documentation link, you just read it once.You will get clear idea.
https://www.dropbox.com/developers/start/setup#ios
Happy Coding!!!
I have dilemma about Memory releasing IBOutlet object.Do anyone please suggest what to do when we create IBOutlet object without property, need to release it?? if need to release... why we are releasing it
The answer is YES.
The runtime connects the objects to IBOutlet using [setValue:ForKey:]. This function will find the private instance variables, retain the target and set it to the instance variable. Please visit here iOS Developer Library to know more.
I highly recommend you to read the article because many iOS framework accesses properties by Key-Value compliance ([setValue:ForKey:] or [valueForKey:]), instead of directly calling getters/setters/instance variables.
IBOutlet does not change the ownership semantics of properties. If you do not use ARC you have to release retained objects as with any other property.
Just Set it to default, which is "Weak". Then you are fine with ARC.
Why not just have a private IBOutlet property, to make things clearer and more explicit. I always do this personally:
MyClassName.m
#interface MyClassName ()
#property (nonatomic, weak) IBOutlet NSObject *myPropertyNameForAnOutlet;
#end
#implementation MyClassName
...
#end
You are not the owner of that object. so no need to release IBOutlet object.If you are using #property (nonatomic, retain) on IBoutlet object then you must release that object in dealloc.
Take a look at Advanced Memory Management Programming Guide
You must not relinquish ownership of an object you do not own
Answer is YES...
i was confused about that too, but try this:
open a xib file
onen assistant editor window and get the .h file code near your XIB IB file
chose an object in IB file (an object with no reference to any var)
ctrl click on it and chose: "new reference outlet" button
drag the line to your .h code file in the #interface{ } section
give a name to your new var ("aaa")
(note that no property "aaa" is created)
now Xcode has done all the magic for you, and...
in .m file you can find, in dealloc method:
- (void) dealloc {
[aaa release];
[super dealloc];
}
so... if apple release it, it seems that the default IBOutlet vars loaded via XIB file are retained...
EDIT:
here's the point in apple doc:
You are not the owner of the object, therefore you do not release it.
You become the owner by retaining, copying or creating (init/alloc) an object. Only then you are you (one of the) owner(s) of the object, and need to release it when you are done with the object. Fore more info check
Cocoa core competencies - Memory Management
I hope this explains why you do not have to release the object.
Even though you didn't set it as property, the property is refer to setter and getter methods. When you use an object you should always remember to release it. The property is unrelated with memory issue.
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'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"
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?