call the function(InApp Purchase) - iphone

how can we call the defined function on button action in objective-c on iPhone.
for example:
we define the function as follow
-(void)abc
{
//
}
now how can i call this function on the button action

What does "on button action" mean? You need to read a basic tutorial on using Interface Builder/Xcode. Apple's "Getting Started" documents may not be simple enough.
In short, you need to drag from the button to your controller object, and select the action. For this to be enabled, you need to declare it as -(IBAction)abc;

You have to create an -(IBAction)abc:(id)sender; IBAction in your .h file, and a respective method in your implementation (.m) file. In Interface Builder, you then have to right click on the button, and from the circle next to Tap Up Inside drag over to your File's Owner box. Then let go over abc and you're golden.
Implement the code you want to run in your abc() method.

Related

SenTesting for iOS programmatically press button?

So in some of the apple sample code I see things like this for application testing:
[viewController press:[calcView viewWithTag: 6]]; // 6
However when I try to do that with my own viewcontrollers/views all I am getting is "No visible interface declares press"... where is the documentation for application SenTesting on iOS, and in particular how do you go about doing UI testing (programmatically press a button, etc) within iOS?
Without seeing the sample code, I would guess that the view controller has a UIAction -press:. It should expect the nib to wire button presses to this action.
Instead of simulating the event, the test directly calls the action touch event would call.
After looking a bit, I think you may want how to programmatically fake a touch event to a UIButton?.
First you need to get a reference to the UIButton. If it's already set as an outlet in the view controller, you can use that. So, I'll assume your viewController has an IBOutlet for that UIButton named 'button'
[viewController.button sendActionsForControlEvents:UIControlEventTouchUpInside];
For the Swift 2.0 solution
viewController.button.sendActionsForControlEvents(.TouchUpInside)

How to see activities while performing actions?

In my iPhone app,
I am working with XIB file.
There is a segmented control,
But there is no IBAction associate with any field,
Whenever I am selecting or touching an segment which method from my code will be called ?
Can I trace or see it in the xcode.
Actually I am looking through some complex code and could not catch the methods by breakpoints ....
Like this Question of stackoverflow.
How to print or see method call stack in xcode?
If you want to see the target method you can right click the controller and see the the method associated with segmented control. If you want to add add some target method with segment controller then do this -
Right click the controller
drag the plus button of desired action(like valueChanged ) to .h file,one popup will come
enter the action name click connect
now go to .m file and write your logic in action
First of all, you do not associate any IBAction with the segmented control's "fields". You associate an IBAction with the control itself.
So, to get you started:
Create an IBAction like :
-(IBAction)segmentChanged:(UISegmentedControl *)sender;
Bind that action with the "Value Changed" event of your UISegmentedControl object
Now every time the segment changes, this method will be fired.
To get the selected index use:
uint selectedIndex = [sender selectedSegmentIndex];

iPhone: IBAction vs Selector

I have a Button1 which has IBAction. Also I set target and action for my button
- (void)setTarget:(id)target action:(SEL)action {
[self.Button1 addTarget:target action:action
forControlEvents:UIControlEventTouchUpInside];
}
So when I pressed the button firstly IBAction did what he should, and than action that I set to button. Is that order always be like that ?
If you are loading you view or view controller from a nib file then yes the pattern will always be the IBAction even first followed by the target you have added to the button.
In effect adding an IBAction in Interface Builder is really just telling IB to call ["UIControl" addTarget:"id" forControlEvents:"UIControlEvent"], and you can add multiple targets to a UIButton.
In effect your code will load everything from the NIB file first (if you are using initWithNib:named:), so this will call the addTarget function on the button first with the action you have specified in Interface Builder, then at some later point the setTarget function you have above will get called, which will add another target action to the button. A UIControls targets are stored in an array which is accessed in order and will trigger if control events are met in the order they were created in.
If you look in the header file for UIControl (the super class for UIButton) you will see that NSMutableArray* _targetActions is an array. So the order is guaranteed to fire like this unless you reorder this array after it is created at some point.

General advice on tracking an object's changes

I have an option menu where a user can change the application's settings. I need to track the changes. There is a DONE button, I want to make changes to the data model only when the button is pressed.
My question is, I am not sure the best way to track the changes. I don't want to introduce a giant if blocks in the doneButtonPressed button. Any general advice?
Well, the generic answer is: add callback to your controls in your options screen.
For example if you are using UISlider, then you have to customize it slightly. Probably create a subclass, that would receive touch events and then you redirect them to the delegate. OR you can use this one: RCSwitch
If you are using UIButton's then it's even easier: just add action to it.
After that you can create method like:
-(void) controlDidChange:(UIView*) control {
//mark changed items here
}

Call an onclick method from one view to another iphoneprogess hub iphone sdk

I have a view with a button which downloads files when clicked.
Question I have is is it possible to call that click method from another view>
THanks
You have a method there. Something like onBtnClk. You can create in another view an instance of your viewController, that contains this method and send [myViewController onBtnClk].
This may be a good case to have some other class(maybe a singleton?) handle downloads, then have your click: method interact with the downloading class.
I know that everyone hates singletons, but this may be a good time to use one.