Can anyone tell me how I can fetch the Object ID of an NSObject though code? See the Screenshot:
The Object ID in Interface Builder is only an internal book-keeping value used by IB when deserializing/serializing XIB files, and does not exist when the Application runs.
You want to use tag, or alternately, a property/outlet.
Object ID is something meant for the IB to understand the difference between the objects.
There is no such API or a way available to fetch the Object ID of any component.
Related
Please refer to this image, I have declared property matchResult, why couldn't I access it from its instance?
The other property "score" works, why?
The code runs in iOS6 environment.
Please open image in a new tab if you couldn't see it clearly.
Thanks
It seems that you have defined the property in the implementation file "CardMatchingGame.m",
using a class extension. That means that the property is only available in the #implementation block of this class.
To make the property accessible from other classes, move the declaration to the public #interface in "CardMatchingGame.h".
It is declared within the .m file and therefore not visible from "external". It does not matter that you access it from a method of the same class. You acces an external interface by referring to self.game.matchResult.
If game equals self then you could access self.matchResult. But I do not think it does because you fetch self.game from the array self.cardButtons.
So, you will either use self.matchResult if you are referring to self or you will have to move the property to the interface definition within the .m file.
I'm new to Titanium Properties API. I'm getting a weird error when using setObject() method.
Following is my code.
Titanium.App.Properties.setObject(view.idAttr, view);
Where view.idAttr is a string acting as a key for this property and view is a View type object. Upon calling above method, I get following message.
2012-09-14 17:47:25.947 SumMeUp[14033:4a03] *** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '[object TiUIView]' of class 'TiUIViewProxy'. Note that dictionaries and arrays in property lists must also contain only property values.
I couldn't understand this behavior. If anyone knows a solution to, please reply.
Thanx
setObject() is meant for objects only, not for views.
A object would be something you write yourself in JavaScript.
Even if it could, it would be bad behaviour of the app to store it in a property. Remember the property is being stored cross-session. So if you want something stored, store data there to generate the view later again, not the view itself. Also saves a lot of memory!
How would you solve this? When the app starts, four objects of a class are created. These objects have names you know because you named them yourself. From a viewController you can access these objects and call a method (which they all got) which creates a UILocalNotification. (So in the end you've got four notifications running.)
Two questions:
How do you name the notifications (differently)? As far as I know is it not possible to access the object name to use the string as name when creating the notification? (Which would be the best solution?)
When the notifications are fired, how do you access/cancel them from another viewController when you don't know the names?
Thank you!
Set tags for all objects, and set same tags for notifications, they generate.
I'm new to programming in Cocoa, so I'm still struggling to grasp some basic concepts.
What I want to do (as an example) is write an application with multiple NSTextFields. However, these NSTextFields need to be linked to separate classes. Additionally, each separate class needs to be able to get and set data from each other.
I tried to add methods to tackle this problem, to no avail. Let's say this is a method in the textbox's original class, and I want to call it from another class.
-(void)settextfield:(NSString*)stringy;
{
[TextField setStringValue:stringy];
}
Here's the calling code (we're calling this from another class, TestClass)...
-(IBAction)test:sender;
{
[BundleBrowseTextBox settextfield: #"Testy"];
}
Nothing happens. There's probably some obvious way to do this, but I haven't been able to unearth this via Google searches.
My mistake was that I was calling the class method instead of the instance... you can call the instance via IBOutlets and defining those outlets properly in Interface Builder.
You need to make sure the pointers you are using are not nil.
One odd/convenient thing about objC is that you can pass messages to nil and it won't crash.
If I'm right in assuming you're trying to set the text in an instance of BundleBrowseTextBox, you should call the settextfield: message on the instance name, rather than on the class name (if BundleBrowseTextBox IS the instance -- rather than the class -- you should really avoid capitalized instance names for clarity). i.e.:
-(IBAction)test:(id)sender;
{
// Assuming bbtBox is defined as an instance of BundleBrowseTextBox
[bbtBox settextfield: #"Testy"];
}
I believe you forgot your parameter type in your original post
this...
-(IBAction)test:sender;
{
[BundleBrowseTextBox settextfield: #"Testy"];
}
should be
-(IBAction)test:(id)sender;
{
[BundleBrowseTextBox settextfield: #"Testy"];
}
That aside if you understand the difference between class and instance as you say you do.
Then it would be nice if you would show us the rest of your implementation and interface.
The problem is probably not in the code snippets you showed us.
How can I iterate over an instance properties in objective-C ?
I need to get all the properties values without having to specify them.
This is the only solution I've found so far, but I was wondering if it could be done with less code: Get an object properties list in Objective-C
thanks
EDIT : #EmptyStack has the right idea - follow his link in the comments on the question :)
Take a look at these methods : http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/class_copyPropertyList
They let you (amongst other things) find all the properties that a class implements. You can then run through that array of properties and call performSelector: for each property you are interested in.