So how can i make a button click other buttons in objective c for iOS? I use xcode.
IBOutlet UIBarButtonItem *save1;
IBOutlet UIBarButtonItem *save2;
IBOutlet UIBarButtonItem *save3;
IBOutlet UIBarButtonItem *save4;
These are the buttons, I want that button "save4" click button "save1", "save2" & "save3".
I understand the actions and outlets and I have that all connected, but I just wan't the code to click other buttons, the problem I have is that those buttons are on another view and I tried many code but they don't work. Here is a download link: Download
I think you are confused between "Outlets" and "Actions". For handling button clicks, you must define "Actions" for your buttons. For eg, write the following code in your view controllers .m file:
- (IBAction) saveOnePressed:(id)sender{
// Button one is pressed. Do your actions here.
}
And connect your button to this action.
EDIT:
As per rmaddys suggestion:
You can define the Action for your fourth button as the following:
- (IBAction)saveFourPressed:(id)sender{
// Here you can call all the other 3 actions
[self saveOnePressed:nil];
[self saveTwoPressed:nil];
//......
}
Related
I have a UIButton. I bound a target as follows.
[button addTarget:self action:#selector(myFunction)
forControlEvents:UIControlEventTouchUpInside];
When i click my Button multiple times quickly it invoke the target function multiple times.
On Tapping button i present a new View controller.
when i click 3 times quickly then my new view controller is shown 3 times.
This is something stupid. Whats the point of triggering the function again once the View has been shifted to a new View controller. Why the Hell Apple do such stupid things ?
Any Help please?
First of all its not apple bugs. It should be handle manually. So follow these step
First make your global instance of your button then do this
.h file
#property (weak, nonatomic) IBOutlet UIButton *btn;
.m file
- (IBAction)myFunction:(id)sender
{
self.btn.userInteractionEnabled = NO;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.btn.userInteractionEnabled = YES;
}
Take one global bool flag like "isItDone" or it declare in singleton class.
in "myFunction" set it as false
which View controller you push on that function in that class's "ViewDidAppear" method set as true.
it will help you.
I have same problem and it is good solution for that to manage it using one global variable.
I think this will help you.
Change your calling function like this
- (IBAction)myFunction:(id)sender
{
UIButton *button = (UIButton*)sender;
button.userInteractionEnabled = NO;
}
and call your function like this
[button addTarget:self action:#selector(myFunction:)
forControlEvents:UIControlEventTouchUpInside];
if you want to store the selection incase you came back to the view controller then only you need to keep a boolean flag to store if its clicked once or not.
Set the IBOutlet to your button, in the viewWillAppear method write,
button.userInteractionEnabled = YES;
and when you click on the button set,
button.userInteractionEnabled = NO;
I've hidden a UIView using
_loginview.hidden = YES
and when I do
-(IBaction)logInButton:(id)sender {
_logInView.hidden = NO;
}
It still doesn't show when I click the button, can anyone help?
I have created a Iboutlet property of UIView and connected it with UIView in storyboard. Also ticked hidden.
Screen shot of hidden view is below(color orange). I also sethidden in programmatically way and still working.
And later on button action I perform setHiden as no and it appeared. Code of IBAction is below:-
- (IBAction)loginBtn{
[hidenView setHidden:NO];
}
You need to setHidden NO on your View when you clocked on uiButton..
(IBaction)logInButton:(id)sender{
[_logInView setHidden:NO];
}
It is working my end by creating this,
#property(nonatomic,strong) IBOutlet UIView *viewLogin; // in controller.h
#synthesize viewLogin; // in controller.m
set outlet property for viewlogin in storyboard
and with following IBAction event,
-(IBAction)login:(id)sender{
[viewLogin setHidden:NO]; }
In storyboard, from connections inspector check that your button is connected properly with a sent event.
Then (if you are performing an async process, maybe login user) try this:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
_logInView.hidden = NO;
}];
witch updates the UI from the main thread.
Just a guess.
Better use setAlpha instead of setHidden.
I'm stumped at why this code isn't working. I have a login button that I want to disable when the user isn't logged in.
I have a UIButton delared in my .h file like so:
IBOutlet UIButton *myBtn;
I've set up a referencing outlet in Interface Builder to this button.
In my .m file, I've tried:
[myBtn setEnabled: NO];
and
myBtn.enabled = NO;
But neither of these disable the button in the conditional statement I'm in. (I want to disable the login button when the user successfully logs in)
I'm able to do this with two other buttons on the same screen, so I know the code is correct. I don't throw any errors, so I think the object exists. The references to myBtn change color in XCode, too, so it appears to be a valid reference.
I must be missing something. What am I doing wrong here? (I'm a Windows developer, relatively new at Objective-C)
It seems ok to me. Are you synthesizing the button? Try
self.myBtn.enabled = NO;
If you're looking for Swift3 solution
var myBtn = UIButton()
myBtn.isEnabled = true
You should be setting up your button as a IBOutlet.
#property (weak, nonatomic) IBOutlet UIButton *myBtn;
That way you can connect that button in storyboards. Which could be your issue.
Then call this to disable.
[_myBtn setEnabled:NO];
Do try this ..
In .h :
#property(nonatomic,retain)UIButton *myBtn;
In .m :
#synthesize myBtn;
And then,replace your [myBtn setEnabled: NO]; code with [self.myBtn setEnabled: NO]; code.
If you are looking for swift code:
var button = UIButton()
button.enabled = false //disable the button
I'm trying to get a custom tab bar for iPhone (iOS 6) and I've got to manage a central button that raises over the bar (based on code, https://github.com/tciuro/CustomTabBar) but now I have to face another feature: buttons must blink when clicked and glossy effect has to be removed. Any suggestion about the best way to get that? I'm still relatively new programming with iOS and its animations.
Thank you very much
What I already have so far:
In MBCenteredButtonVC (main entry in storyboard)
#import <UIKit/UIKit.h>
#interface MBCenteredButtonViewController : UITabBarController <UITabBarDelegate>
#property(nonatomic, weak) IBOutlet UIButton *centerButton;
#end
And its implementation:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tabBar setSelectedImageTintColor:[UIColor colorWithRed:171/225.0 green:233/255.0 blue:8/255.0 alpha:1]];
[self.tabBar setBackgroundImage:[UIImage imageNamed:#"bar-back.png"]];
// Do any additional setup after loading the view.
[self addCenterButtonWithImage:[UIImage imageNamed:#"button-rocketBg.png"] highlightImage:[UIImage imageNamed:#"button-rocketBg-active.png"] target:self action:#selector(buttonPressed:)];
}
Images for each item is defined within views properties using XCode. So, this way, I get a central button raised over the rest and I have changed the color for selected items but I need that they blink while content is being loading (it supposed that could take some time).
I feel that I have to implement this functionality when buttons are pressed:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSLog(#"Selected tab bar item: %i", item.tag);
}
}
but not sure if it the right way and how to do it exactly.
The easiest way to get started with animations on iOS is probably to use the UIView animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations method.
Documentation here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW111
Any values that are animatable that you change in that block will be animated.
Core Animation is extensive, and this barely scratches the surface of what can be done, but it might be enough to get you started.
I have an CustomUIScrollView that have many CustomUIButton inside (each button is a news item that have an image and title --> each button have a news ID
When touch inside button, the touchupInside event fire --> everything is OK
But i want when touch in button, a detail news Page, detailViewController, will create and push into navigationController (like BBC NEWS app in Store) and the detail Page will load webpage has ID equal with ID of Button we has touched.
My tableviewController is rootViewController, how can I pass event with ID data from Button in Scrollview inside UITableViewCell to my rootviewController to push a new DetailViewController
Thank in advance. (See picture make more easy to understand)
enter code hereHi i used this code try this..
in this code i pass button tag form calling method and compare to called method and then take your action whatever you need.
Thank You
-(IBAction)btnpress:(id)sender
{
UIButton *btn = (UIButton *)sender;
NSLog(#"%d",btn.tag);
if(img_alphabet.tag == btn.tag)
{
}
}