How to see activities while performing actions? - iphone

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];

Related

Close popup UITableViewController view

How do I know when the view got closed? Am currently using the delegate pattern, capture viewDidDisappear to fire the event... Is this the correct one to use? Downside of viewDidDisappear is that when my view move to a sub-view the event still fires.
Its a custom view that i made that exptend UITableViewController... In that table you got a list of options that you manage, so when moving between those screens I don't want my event to fire.. I only want it to fire when I close the actual view.
now just see when your UITableView begin open at that time you set the bool value like...
first define this variable global in your .h file like bellow
BOOL isTableOpen;
and after that in your .m file
set yes when your tableview is open with button tap event or anything else which you used...
isTableOpen = YES;
after when your pop-up view or UITableview closed at that time set value NO like
isTableOpen = NO;
and check in your viewDidDisappear: that if isTableOpen is true then do nothing otherwise yes...
-(void)viewDidDisappear:(BOOL)animated{
if(isTableOpen){
//call your method which you want...
}
}
i hope this help you or get some Idea ..
:)

How to load existing TableViewController on click of button iOS5

I created UIExamsTVC using storyboards.
Once cell is clicked, it takes me to UITestVC.
UITestVC has 10 questions, When I get to the last question #10, there I have a "Done" button. I would like to go back to the original UIExamsTVC once the 'Done' button Clicked.
In: UITestVC.m
#import UIExamsTVC.h
(on button click)
[self.navigationController pushViewController:UIExamsTVC animated:NO];
Compile error - Unexpected Interface name
How can I do this?
If you want to go back then you don't want to push anything new...that's just adds to the existing stack. If you got to the UITestVC through a push, you want a "pop" in order to go back. If you got there by presenting it modally, you want to "dismiss" it.
(What your actual error is telling you is that you can't use the name of a class when the method you're calling wants a reference to an object.)

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)

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.

call the function(InApp Purchase)

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.