gpt4 book ai didi

iphone - 如何使 Xcode 自动完成委托(delegate)方法?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:09 29 4
gpt4 key购买 nike

此代码使用委托(delegate)

[[[UIAlertView alloc] initWithTitle: @ "Error" message: @ "You can leave the text blank" delegate: self cancelButtonTitle: @ "Quit" otherButtonTitles: @ "OK", nil] show];

有问题的代表是:

 (void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) buttonIndex {

我的问题是:您如何为 Xcode 委托(delegate)方法自动完成?

在 Eclipse 中,您可以从 Source 菜单选项 Generate Delegate methods 中执行。

问候和感谢!

最佳答案

你的类应该支持 UIAlertViewDelegate 协议(protocol)

@interface YourClass : NSObject 
<
UIAlertViewDelegate
>

开始输入“破折号” - 你会看到所有支持的方法包括 UIAlertViewDelegate 方法。要减少自动完成方法列表:键入 -alert

只需使用“转到定义”即可查看所有“UIAlertViewDelegate”方法。在您的 XCode

中开始输入以下方法之一

enter image description here

如果方法在 @required 部分下,您必须在您的委托(delegate)对象中实现它,否则您将收到警告。如果在 @optional 方法下,您不必实现这些方法中的任何一个(您不会收到警告),但在大多数情况下,您应该这样做以让它按预期工作。

关于iphone - 如何使 Xcode 自动完成委托(delegate)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18763362/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com