clicking UIButton? - ios

is it possible to click UIButton and to call its action through Programming without clicking?

You can just simply call the method associated with your UIButton action as follow :
- (IBAction)myMethod:(id)sender {
// some code here
}
When you want to fire an action :
[self myMethod:nil];

Yes you can do it programmatically just send a event to button

Well I guess you can get a little help from a friend of mine that help me a lot to get start with objective C and Iphone development Basics. maybe you already have seen him but if not here is the link http://www.youtube.com/watch?v=B7jB0D3Y7Ws&feature=channel pretty easy to understand.

Related

iOS Delegates instead of passing data through a segue

I'm trying to learn how delegates work and wrap my head around the concept. I'm finding I get some of the ideas. I understand you use it to pass data from one view controller to another, however wouldn't it work the same if I just sent data from a segue and every time the 1st view controller would appear, it would use that data?
So for example I have 2 view controllers.
1 is homeViewController and
2 is editViewController.
I have a variable titled "addressOfHome" which is a string in homeViewController(1).
In homeViewController under the method "viewDidAppear"
I also set the addressLabel = addressOfHome.
Then I just pass the data from editViewController(2) to homeViewController(1)
when the segue's destination vc is homeViewController ?
I'm terrible at explaining things so I apologize for that, but I gave it my best shot. Thanks for your time!
Delegates are mainly used to "trigger action" on an object from another one.
An object delegates a way to handle something to someone else, for example when you click on an UIAlertView button, if its delegate is set on a viewController, alertView:clickedButtonAtIndex will be executed on the VC, which can so react as it want
I'm terrible at explaining things
Haha, yes, you are !
A delegate isn't for that - a delegate is a way to over-ride the default behaviour of some feature(s) of a class, without creating your own sub-class. See this post : How does a delegate work in objective-C?
Are you trying to understand how delegates work (in which case, I don't think your example is one that requires a delegate) or are you trying to implement the functionality you describe, and think that a delegate is the way to do it? (I think you actually want a data source).

Is there a way to "capture" all the UIButton taps inside an app?

I want to be able to track what buttons my users are tapping.
Is there a way to "capture" or "log" all the button taps inside my app?
I was thinking about method swizzling but I really rather not get into that.
Aspect Programming may help you. Have a look at this library :
https://github.com/steipete/Aspects
Basically you do something like :
[UIButton aspect_hookSelector:#selector(whateverSelectorYouWantToHookOn:)
withOptions:AspectPositionAfter
usingBlock:^(id<AspectInfo> aspectInfo) {
NSLog(#"UIButton called");
}
error:NULL];
Have a look on the AspectInfo for more information on the instance called.
Buttons can have multiple actions attached to them. You could always add a logging action to each of your buttons. The action method receives the sender, so you could log information about the button that was tapped.
You can subclass UIButton to add logging. The accepted answer on
objective C: Buttons created from subclass of UIButton class not working
has a good explanation on why this is one of the few instances that subclassing may be useful.
Basically UIButton inherits from UIControl and UIControl Class Reference states
Subclassing Notes You may want to extend a UIControl subclass for either of two reasons:
To observe or modify the dispatch of action messages to targets for particular events
To provide custom tracking behavior (for example, to change the highlight appearance)

How to implement addTarget:atSelector:forControlEvent: on the sending object?

I'm creating custom control that behave slightly like a UISlider. I would like to allow objects using this class to be able to addTarget:atSelector:forControlEvent: the event would be here UIControlEventValueChanged.
How can I make my custom UISlider like object send the selector on the target upon value changed ?
Okay, just make your object a subclass of UIControl and you're good to go.
here is the tutorial link which is having sample code as well at the end.
http://www.raywenderlich.com/36288/how-to-make-a-custom-control
hope this will help you.

How to create a flat UIActionSheet

Today's trend in apps includes flat designs, and now I am doing an app that follows with this trend. My problem now is how to create a UIAcionSheet that match with my App Screen's flat UI Design. In relation with this, I saw Instagram's action sheet and I found it interesting. I wish to have that design in my app. Anyone knows how to implement this in ios apps? I have provided a screen shot from instagram app.
You can use RDActionSheet from git
https://github.com/reddavis/RDActionSheet
I hope it will help you..!!
yes,
you can use https://github.com/reddavis/RDActionSheet and also u can change image and color of text and background image of action sheet
You can use FlatUIKIT from Git
https://github.com/Grouper/FlatUIKit
Go through the documentation & you will know how to use it. Awesome collection of Flat UI classes.
You can create a subclass CustomActionSheet derived UIActionSheet,
and create a method called CustomUI in it. Design your code here.
use CustomActionSheet like UIActionSheet, except must call method CustomUI of subclass in willPresentActionSheet delegate:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
if ([actionSheet isKindOfClass:[CustomActionSheet class]]) {
CustomActionSheet *sheet = (CustomActionSheet*)actionSheet;
[sheet CustomUI];
}
}

disable CPPickerView not working

I'm making an iPhone/iPad app where I have PickerView. For PickerView, I am using CPPickerView.
I'm trying to disable this pickerview and to do that, I wrote this code:
[realEstatePV setUserInteractionEnabled:NO];
However, above is not working. I can still move the CPPickerView.
Any idea how to get this done?
I had the same problem. So i updated the CPPickerView, and its very easy.
Open CPPickerView.h and add a method declaration
- (void)enabled:(BOOL)val;
Now open CPPickerView.mand add implementation method.
-(void)enabled:(BOOL)val {
self.contentView.scrollEnabled = val;
}
Its done......
Now You can disable CPPickerView like this.
[realEstatePV enabled:NO];
To enable again use
[realEstatePV enabled:YES];
Hope this helps.

Resources