gpt4 book ai didi

ios - 如何使用 shouldPerformSegueWithIdentifier 在正确的时间显示 HUD?

转载 作者:行者123 更新时间:2023-11-29 12:26:16 25 4
gpt4 key购买 nike

背景

  1. 导航 Controller View
  2. 带有包含 ftp 信息的单元格的表格
  3. Cell segue 将连接到 ftp 服务器并显示列表
  4. shouldPerformSegueWithIdentifier 将检查服务器的连接情况
  5. 如果它能够连接到 ftp 服务器,它将执行 prepareForSegue

单击单元格时,我会向 HUD 显示“正在连接...”,当它验证时,推送到下一页。

问题:HUD 没有立即显示,而是在推送到下一个 View 之前显示。为了以防万一,尝试了各种不同的 HUD,但都失败了。我确定这不是 HUD。

问题:如何在单击单元格时立即启动 HUD? shouldPerformSegueWithIdentifier 是开始显示 HUD 的正确位置吗?我尝试使用 dispatch_async 或 sync,但我必须返回 YES/NO 来确定是否应该执行 segue。

-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if([identifier isEqual:@"ConnectServer"])
{
self.HUD = self.prototypeHUD;
self.HUD.textLabel.text = @"Connecting...";
[self.HUD showInView:self.navigationController.view];
NSManagedObject *obj = self.serverList[[self.tableView indexPathForSelectedRow].row];
return [self checkServerConnection:obj];
}
}

最佳答案

您可以通过 UITableViewDelegate 协议(protocol)实现 tableView:didSelectRowAtIndexPath:。当用户点击单元格时,会立即调用此方法。然后,您必须检查此单元格是否应触发您的 HUD(假设您有不同种类的单元格,否则您可以省略检查)。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (<check if the appropriate cell was tapped>) {
self.HUD = self.prototypeHUD;
self.HUD.textLabel.text = @"Connecting...";
[self.HUD showInView:self.navigationController.view];

}
}

关于ios - 如何使用 shouldPerformSegueWithIdentifier 在正确的时间显示 HUD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29003961/

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