English 中文(简体)
对自定义事件执行IBAction
原标题:Execute IBAction on a custom event
  • 时间:2010-10-24 23:57:23
  •  标签:
  • cocoa

我如何能够基于另一个事件运行IBAction?例如,我可以使用一段代码来运行IBAction。

我想做的是让两个不同的按钮运行一个或多个IBActions。

最佳回答

您可以将多个按钮挂接到同一个IBAction,因此可以这样做。

但IBActions只是方法。例如,如果您有一些操作doSomething:,您可以在对象上调用它:

[obj doSomething:nil];
问题回答

IBAction只是接口生成器的一个提示。这实际上是另一种表达空虚的方式。

#define IBAction void

So there is nothing special about it. In Interface Builder, you can connect touch event for different buttons to the same IBAction. You can also call IBAction methods from another IBAction method. Use the sender argument to identify the source of the event.

例如

-(IBAction)buttonTapped:(id)sender {
    UIButton *btn = (UIButton *)sender;
    NSLog(@"tapped: %@", btn.titleLabel.text);
    [self anotherIBAction:sender];
}




相关问题
Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签