what does gtk_adjustment_value_changed method signify.
Can i increment gtk_adjustment_value_changed value instead of value
Regards,
iSight
If you look at the documentation for gtk_adjustment_value_changed(), you will see that there is no value for you to increment. This method tells the GtkAdjustment object to emit a notification to any object that is listening to the value-changed signal. You shouldn't have to use it in a normal application.
Related
I am creating a GUI with GUIDE and have added a slider to my GUI. Afterwards, I have added a listener to my slider
myListener = addlistener(handles.mySlider,'Value','PostSet',#(src,evnt)myCallback(src,evnt, handles.figure1));
In the function myCallback I do some changes to an object I plot on an axis. I also made this object selectable such that another callback is called once the user clicks on the object. I would now like to initialize the slider with the appropriate value for the object just having been selected, but without calling the function myCallback.
That is, I need something like
setWithoutCallingListener(handles.mySlider, ValueOfSelectedObject);
Is that possible?
The easiest way to temporarily deactivate a listener is by adding a flag to the handles structure.
For example, at the beginning of your initialization routine, you set handles.isInitializing=true; guidata(hObject,handles);,and add if handles.isInitializing, return; end to the beginning of the listener callbacks. Remember to set the flag to false at the end of the initialization routine.
Alternatively, don't use listeners, but instead have all UI-element callbacks call a function updateUI(handles) (in addition to potential input checking; for example you may want to ensure that the slider can only take on integer values) which takes care of (1) adjusting all interdependent values (e.g. if you have a slider and an edit text box that need to be synced), and of (2) spawning whatever process you need to update the plot. This has the advantage that the UI element callbacks do not fire if you modify the element via a function.
I have a method called Display. Can somebody explain me the difference of calling the same method in the following two ways.
[self Display];
[self performselector:#selector(Display)]
- (void)Display {
NSlog(#"Data");
}
both are basically the same with one minute difference.. #selector gives a name to your method which you can pass around as an attribute to other objects or in other function calls.
Like if you want to send a message to other object and you want to send display as an attribute then you will have to give it a name using #selector and thus you can send it.. its a pretty vague concept.. hope this helps.
and to quote apple documents...
"However, the performSelector: method allows you to send messages that
aren’t determined until runtime. A variable selector can be passed as
the argument:
SEL myMethod = findTheAppropriateSelectorForTheCurrentSituation();
[anObject performSelector:myMethod];
The aSelector argument should identify a method that takes no
arguments. For methods that return anything other than an object, use
NSInvocation."
[self Display] is shorter and easier to read, write and comprehend.
[self performSelector:#selector(Display)] makes it possible to execute arbitrary selectors. If you save the selector in a variable, then you can execute it later on without knowing the method you invoke. It is therefore more flexible. Even better: you can pass selectors and objects to other objects and let them invoke it for you when necessary. An example why you want to use this is the NSUndoManager which simple invokes a selector to undo an action if the user executes the Undo command.
I do not think that there is a big difference between examples you provided, but perform selector is very useful when you for instance wanna move execution of your method to the background thread.
[self Display]; is a call to a known method on a known object.
It's easy to give it some params if your want : [self DisplayWithParam1:(NSString*)aString param2:(int)aNumber param3:(NSDictionary*)aDict
[self performselector:#selector(Display)] is a call that allows you to call a possibly not known method on a possibly not known object type.
Let's imagine you have many kind of classes that all respond to a given protocol that require to have the Display method implemented. You put some objects of thoses different classes in an NSMutableArray. When parsing the array later, you will get id typed objects.
So calling[myArrayObject Display]; will work at runtime but will generate a warning at compile time as id does not support any method of course, even if you know that this object supports the method.
To prevent thoses warning, call [myArrayObject performselector:#selector(Display)];.
The problem with that call is that is harder to pass some parameters.
performSelector:withObject:withObject:
Sends a message to the receiver with two objects as arguments.
- (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject
Parameters
aSelector
A selector identifying the message to send. If aSelector is NULL, an NSInvalidArgumentException is raised.
anObject
An object that is the first argument of the message.
anotherObject
An object that is the second argument of the message
Return Value
An object that is the result of the message.
Discussion
This method is the same as performSelector: except that you can supply two arguments for aSelector. aSelector should identify a method that can take two arguments of type id. For methods with other argument types and return values, use NSInvocation.
Availability
Available in Mac OS X v10.0 and later.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocSelectors.html
The #select call is faster. Generally the uglier (and less dynamic) the code you have in Objective-C, the faster it runs. Here, the selector call bypasses the usual call to objc_msgSend().
I wouldn't recommend writing code like this if you can avoid it. Selectors are somewhat common in Cocoa, but if you're using it for a speedup it's really not worth it. objc_msgSend() is highly optimized and very fast.
I was told the only/best way to do this is to store the variables in a struct and pass the struct, however it's turned into a gpointer and I can't seem to be able to turn it back into a struct to retrieve the data.
If there is any other way I would like to use that too.
Cast your struct back to the proper type in your signal handler.
MyVariables *vars = (MyVariables *)user_data;
PS. Oh, yeah, and don't forget to allocate your struct; if you pass a local variable, it will have disappeared by the time your signal handler is called.
Hey guys,
can anyone explain me what (id)sender exactly means? I have seen it in so many actions and I don't know how to set this sender id.
- (IBAction)publishStream:(id)sender {
// do something
}
Furthermore, can you tell me how I can set this sender id in code?
Thanks, Cheers, doonot
'id' is a type -- specifically, it's the type of an untyped pointer to an object. A variable of type 'id' can point to any objective-c object. In the case of an IBAction, it's common to have a single parameter named 'sender' that is the object sending the action. Any type of object can send the action, so the type of the 'sender' parameter is 'id'.
Using that you can re-direct several ui "widgets" to the same handler function. You can then use the "sender" to know which one generated the message.
Well an ID is basically a blank type, so it's whatever type of object that called it, I don't believe that you actually set the sender, it's just the object. So say a UIButton called my IBAction, then whatever the UIButton happens to be will be the sender.
actually, sender is Control which invoke the event.
like,
if if you TouchInside the button and you had attached to your method.
then that button will be sender here.
I have an Action Sheet popping up and I want to pass a certain argument to a button processing method.
For example:
I have a table and I want to pass to a button processing method row number that was selected in a table.
How can I achieve this?
You would have to set this in your delegate ahead of time. You can then use this value when your delegate receives the button press notification.
If it is an integer argument, put it as the tag property of the action sheet. Otherwise, you can subclass the action sheet and put variables there, or use associative references.
if you want to pass an integer, use UIActionSheet.tag.
if you want to pass a NSString, use UIActionSheet.accessibilityValue.
these are simple and easy. no need to create an instance variable.