ibaction

How to define which button pressed if they both have same IBAction?

亡梦爱人 提交于 2019-11-29 09:33:19
I have two UIButtons (I create them using IB), which connected to File's owner with the same IBAction, how can i define which of them are pressed? Your action can be implemented like this: - (IBAction) buttonTapped: (id) sender // you can also replace id with UIButton* Then inside this method you can check by -isEqual: method - (IBAction) buttonTapped: (id) sender { if ([sender isEqual:referenceToOneOfYourButtons]) { // do something } else if ([sender isEqual:referenceToTheOtherButton]) { ... } } Alternatively you can set up different values to tag property of buttons and then: - (IBAction)

What's the best way to call an IBAction from with-in the code?

喜夏-厌秋 提交于 2019-11-29 01:02:48
Say for instance I have an IBAction that is hooked up to a UIButton in interface builder. - (IBAction)functionToBeCalled:(id)sender { // do something here } With-in my code, say for instance in another method, what is the best way to call that IBAction ? If I try to call it like this, I receive an error: [self functionToBeCalled:]; But, if I try to call it like this (cheating a bit, I think), it works fine: [self functionToBeCalled:0]; What is the proper way to call it properly? Jakob Borg The proper way is either: - [self functionToBeCalled:nil] To pass a nil sender, indicating that it wasn't

Custom UITableViewCell and IBAction

我是研究僧i 提交于 2019-11-29 00:39:39
I have a custom UITableViewCell on which I have added a button, I have associated that button on an IBAction in my viewController. Now the problem that i am facing is how do I know from which cell that button was created. When I present my viewController which has a table in it and has multiple rows (custom UITableViewCell), now when the user presses the button the action is getting called, but how do I know which row was it. Because based on the row index I need to store some value. Edit: I have some clue on it now, but still I am not sure how will I do it, so it seems like on my

how to access from UICollectionViewCell the indexPath of the Cell in UICollectionView

孤街浪徒 提交于 2019-11-28 18:21:37
i want to animate the UICollectionViewCell when action is called. i have done UICollectionViewCell in Interface Builder , the UICollectionView also. Now i want to get the correct indexPath at my actionBtnAddToCard method. thats the way i try it now (method in ProduktViewCell.m): - (IBAction)actionAddToCart:(id)sender { XLog(@""); // see this line NSIndexPath *indexPath = ??** how can i access the correct indexPath**??; SortimentViewController *svc = [[SortimentViewController alloc] initWithNibName:@"SortimentViewController_iPad" bundle:[NSBundle mainBundle]]; [svc.collectionViewProdukte

UIButton event 'Touch Up Inside' not working. 'Touch Down' works fine

牧云@^-^@ 提交于 2019-11-28 10:00:46
I've got a UIButton in a UIView, which is in a UIViewController that I've allocated and inited from a .xib file. When hooking an IBAction up to the 'Touch Down' event of a UIButton it triggers correctly. But if I hook it up to the 'Touch Up Inside' event it doesn't respond. Other events don't work either. 'Touch Drag Enter', 'Touch Drag Exit', 'Touch Up Outside' etc. Only Touch Down. Does anyone have any idea why this might be? The button is a simple rounded rectangle button in a view controller. I have loaded the view controller as such: -(void) pushNewViewController { MyViewController*

Pass different parameters to an IBAction

给你一囗甜甜゛ 提交于 2019-11-28 06:59:20
My iPhone app has many buttons and I want all the buttons to call the same method, but with different parameters. For example I want tapping one button to call the method myMethod: with the argument @"foo" , and a second button should call the same method but with argument @"bar" . The so called "IBActions" must have one of these signatures: -(void)action; -(void)actionWithSender:(id)sender; -(void)actionWithSender:(id)sender event:(UIEvent*)event; You cannot add any other parameters. Nevertheless you can use sender (which is button1 or button2 in your case) to get the parameter: -(void

How to define which button pressed if they both have same IBAction?

空扰寡人 提交于 2019-11-28 03:03:16
问题 I have two UIButtons (I create them using IB), which connected to File's owner with the same IBAction, how can i define which of them are pressed? 回答1: Your action can be implemented like this: - (IBAction) buttonTapped: (id) sender // you can also replace id with UIButton* Then inside this method you can check by -isEqual: method - (IBAction) buttonTapped: (id) sender { if ([sender isEqual:referenceToOneOfYourButtons]) { // do something } else if ([sender isEqual:referenceToTheOtherButton])

What's the best way to call an IBAction from with-in the code?

扶醉桌前 提交于 2019-11-27 15:36:19
问题 Say for instance I have an IBAction that is hooked up to a UIButton in interface builder. - (IBAction)functionToBeCalled:(id)sender { // do something here } With-in my code, say for instance in another method, what is the best way to call that IBAction ? If I try to call it like this, I receive an error: [self functionToBeCalled:]; But, if I try to call it like this (cheating a bit, I think), it works fine: [self functionToBeCalled:0]; What is the proper way to call it properly? 回答1: The

IBAction inside UITableViewCell not called in iOS 9

霸气de小男生 提交于 2019-11-27 13:23:27
问题 I have a custom UITableViewCell subclass which contains a few IBAction methods wired up from a nib. Under iOS 8 everything works as expected. If the user taps one of the buttons, the appropriate IBAction is called. If the user taps anywhere else on the cell, the UITableView didSelectRowAtIndexPath is called. Under iOS 9, my IBAction methods are never called. The UITableView didSelectRowAtIndexPath is always fired regardless of where the user taps in the cell (button or not). The project is

IOS: one IBAction for multiple buttons

五迷三道 提交于 2019-11-27 12:36:31
In my project I must control action of 40 buttons, but I don't want to create 40 IBAction, can I use only a IBAction, how? If you're using interface builder to create the buttons, simply point them at the same IBAction in the relevant class. You can then differentiate between the buttons within the IBAction method either by reading the text from the button... - (IBAction)buttonClicked:(id)sender { NSLog(@"Button pressed: %@", [sender currentTitle]); } ...or by setting the tag property in Xcode and reading it back via [sender tag] . (If you use this approach, start the tags at 1, as 0 is the