目标C IB插座 [英] Objective C IBOutlets

查看:33
本文介绍了目标C IB插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多个按钮调用IBOutlet的情况下,IBOutlet可以确定按下了哪个按钮吗?

In cases where multiple buttons call an IBOutlet, can the IBOutlet determine which button was pressed?

全部固定并连接好.关键点:对象ID不是发送者标签!标签是属性首页上的独立值.

All fixed and wired up. key point: Object ID is not sender tag! Tag is a standalone value on the first page of the attributes.

- (IBAction)buttonPressed:(id)sender
{
    switch ( [sender tag] )
    {
        case 109:
            NSLog(@"Button 1");
            break;

        case 108:
            NSLog(@"Button 2");
            break;
    }
}

推荐答案

通常,您会将button事件(Touch Down)连接到要在控制器中调用的IBAction方法.

Normally you would connect the buttons event (Touch Down) to the IBAction method you wish to invoke in your controller.

方法原型如下:

-(IBAction) doStuff:(id)sender;

然后,如果需要,可以使用发送者"来验证进行调用的对象的身份.

Then the "sender" could be used to verify identity of the object doing the calling if needed.

IBOutlet将用于从代码中联系UIButton,以设置其文本或属性.

IBOutlet would be used to contact the UIButton from your code, to set its text or properties for example.

这篇关于目标C IB插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆