标签: target-action

如何从自定义控件发送"UIControlEventValueChanged"事件?

我通过子类化UIView创建了一个自定义选择器视图类型的控件.我希望能够从此控件中发送"UIControlEventValueChanged"控件事件,以便我可以在任何使用该控件的视图控制器中注册它.

当我认为应该触发此事件时,如何让我的自定义控件触发此事件?

objective-c target-action ios uicontrolevents

29
推荐指数
1
解决办法
1万
查看次数

禁用操作 - 用户点击tabbar项目以转到根视图控制器

我想在用户点击tabbar项时禁用默认操作.

例如,我有一个Tab5,Tab1,Tab2和Tab3.在Tab1中,用户可以从View1导航到View3(View1> View2> View3).如果用户在View3,并且他点击Tab1,则应用程序将用户带到View1(根视图控制器).我想禁用此功能.我不希望在Tab1上点击以弹出所有视图控制器.我怎样才能做到这一点?

编辑:

这种行为有点奇怪,但在深层次结构的情况下是一个方便的快捷方式!

您可以实现以下UITabBarControllerDelegate方法来禁用此系统范围的快捷方式:

#pragma mark -
#pragma mark UITabBarControllerDelegate

- (BOOL)tabBarController:(UITabBarController *)tbc shouldSelectViewController:(UIViewController *)vc {
    UIViewController *tbSelectedController = tbc.selectedViewController;

    if ([tbSelectedController isEqual:vc]) {
        return NO;
    }

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

iphone tabbar uinavigationcontroller uitabbar target-action

18
推荐指数
1
解决办法
4561
查看次数

如何在NSMenuItem的操作上设置发件人?

Apple文档说传递给NSMenuItem的动作的发送者可以设置为一些自定义对象,但我似乎无法弄清楚如何做到这一点.有没有一种方法我在文档中没有看到某个地方?

cocoa nsmenuitem target-action

11
推荐指数
1
解决办法
5966
查看次数

UIControl:在同一事件中添加多个目标 - 动作对时的调用顺序?

如果我为同一事件添加一个控件多个目标 - 操作对,控件是否会按照我添加它们的顺序将操作消息发送到目标?

我阅读了以下参考文献但未找到答案.

iphone uikit uicontrol target-action ios

9
推荐指数
1
解决办法
581
查看次数

以编程方式创建UIButton事件时,@ objc和IBAction之间有什么区别?

UIButton从情节提要中从中创建事件处理程序时,Swift @IBAction在之前添加func。当以编程方式将事件添加UIButton到时func,Swift会出错,并说我需要@objc在方法前面添加,但是当我添加时@IBAction,它也会编译。

两者之间有区别吗?以UIButton 编程方式向我添加事件时应该使用哪一个?

ibaction target-action swift

3
推荐指数
1
解决办法
667
查看次数

Swift:协议方法作为目标动作中的动作

我想要一个协议:

protocol CameraButtonDelegate: class {
    func cameraButtonDidPress(_ sender: UIButton)
}
Run Code Online (Sandbox Code Playgroud)

因此,我可以将任何客户端分配给按钮,例如:

cameraButton.addTarget(delegate, action: #selector(cameraButtonDidPress), for: .touchUpInside)
Run Code Online (Sandbox Code Playgroud)

但是,它不能编译,因为我必须在中指定特定功能action,例如:

cameraButton.addTarget(delegate, action: #selector(AAPLViewController.cameraButtonDidPress), for: .touchUpInside)
Run Code Online (Sandbox Code Playgroud)

如果我想通过一个按钮将多个客户作为目标,该如何解决此问题?

delegation uibutton target-action ios swift

3
推荐指数
1
解决办法
711
查看次数

Xcode:如何从对象中删除动作?

我需要从对象中删除一个动作,然后添加一个新动作.

我已使用此代码添加新操作:

[Button addTarget:self action:@selector(newAction:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用此代码删除旧操作:

[Button removeTarget:self action:@selector(oldAction:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)

问题是它以某种方式也删除了newAction.

有任何想法吗?

提前致谢 :)

cocoa-touch objective-c uibutton target-action

2
推荐指数
1
解决办法
2866
查看次数

如何将事件添加到UICollectionView单元格?

我想处理点击UICollectionView单元格.尝试使用以下代码实现此目的:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{    
    static NSString *cellIdentifier = @"cvCell";    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];  

    // Some code to initialize the cell

    [cell addTarget:self action:@selector(showUserPopover:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

- (void)showUserPopover:(id)sender
{
     //...
}
Run Code Online (Sandbox Code Playgroud)

但执行中断[cell addTarget:...]了以下错误:

- [UICollectionViewCell addTarget:action:forControlEvents:]:无法识别的选择器发送到实例0x9c75e40

cocoa-touch objective-c target-action uicollectionview

2
推荐指数
1
解决办法
2万
查看次数