gpt4 book ai didi

ios - SCLAlertView 库 - 如何从另一个 View Controller 触发它?

转载 作者:行者123 更新时间:2023-11-28 21:47:33 26 4
gpt4 key购买 nike

我正在使用这个警报库 SCLAlertView。在我的应用程序中,我有一个左侧菜单。当用户离线并且他们试图点击菜单项时,我想触发并提醒。

但由于菜单 Controller 在层次结构中位于主 Controller 下方,因此警报显示在主视图下方。有没有办法将它发送到层次结构的顶部,以便显示在主 Controller 的顶部?

菜单.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (![Utilities checkConnection]) {
// hides the menu
[self.slidingViewController resetTopView];

// Display alert
SCLAlertView *alert = [[SCLAlertView alloc] init];
LNViewController *ln = [[LNViewController alloc] init]; // main view controller

[alert showError:ln title:@"Connection Error"
subTitle:@"Looks like you lost connection. Please connect to the internet and refresh the view."
closeButtonTitle:@"OK" duration:0.0f];
} else {
Dep *dep = [self.menuItems objectAtIndex:indexPath.row];
[self.delegate menuViewControllerDelegate:self selectDep:dep];

// Deselect the row
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}

最佳答案

如果 MenuViewController 的父级是 MainViewController,则不要将 self (MenuViewController) 传递给 showError 方法,而是传递 self.parentViewController 而不是 self。这应该会使警报出现在您的 MainViewController 上。

将显示错误的代码更改为以下内容:

[alert showError:self.parentViewController title:@"Connection Error"
subTitle:@"Looks like you lost connection. Please connect to the internet and refresh the view."
closeButtonTitle:@"OK" duration:0.0f];

初始化 MainViewController 对象不会自动链接或“指向” View Controller 层次结构中的事件 MainViewController 对象。

关于ios - SCLAlertView 库 - 如何从另一个 View Controller 触发它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29523477/

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