gpt4 book ai didi

iphone - 使用一个委托(delegate)来管理两个 UIActionSheet

转载 作者:行者123 更新时间:2023-12-03 18:36:57 26 4
gpt4 key购买 nike

我有两个 UIActionSheets,我想我将用一个委托(delegate)(实例化它们的 UIViewController)来控制它们。委托(delegate)将捕获 actionSheet 调用并尝试找出两者中哪一个引发了事件。

我试图让modalView的标题来区分,但它似乎无效......

这应该有效吗?

如果没有,是否有其他方法可以区分哪个 UIActionSheet 执行了该事件?

或者我是否需要创建两个不同的类,作为每个 UIActionSheet 的单独委托(delegate)?

提前致谢。

最佳答案

我认为您需要 UIActionSheettag 属性。

类似于:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle ... ];
actionSheet.tag = 10;
[actionSheet showInView:self.view];

然后在你的委托(delegate)中:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (actionSheet.tag) {
case 10:
...
}
}

tagUIView 的一个属性,可以在 Interface Builder 中为也出现在其中的组件进行设置。非常方便,尽管我自己从未在这种情况下实际使用过它。

关于iphone - 使用一个委托(delegate)来管理两个 UIActionSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/313639/

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