Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为表视图上的无数据创建警报或标签文本。敏捷的_Ios_Swift_Uitableview_Swift2_Alert - Fatal编程技术网

Ios 为表视图上的无数据创建警报或标签文本。敏捷的

Ios 为表视图上的无数据创建警报或标签文本。敏捷的,ios,swift,uitableview,swift2,alert,Ios,Swift,Uitableview,Swift2,Alert,我有一个表,我想做的是在表结果为空时显示警报。因此,当警报为空时会显示警报,但当警报为满时也会显示警报。我错过了什么??? 在我的视图中: if appUsers.count < 1 { // create the alert let alert = UIAlertController(title: "No Jammers found", message: "Sorry there are no Jammers matching your search prefe

我有一个表,我想做的是在表结果为空时显示警报。因此,当警报为空时会显示警报,但当警报为满时也会显示警报。我错过了什么??? 在我的视图中:

    if appUsers.count < 1 {

    // create the alert
    let alert = UIAlertController(title: "No Jammers found", message: "Sorry there are no Jammers matching your search preferences at this time. Try tweaking your search preferences or try this search later! Hope you find who you are looking for! Happy Jamming! ", preferredStyle: UIAlertControllerStyle.Alert)

    // add an action (button)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

    // show the alert
    self.presentViewController(alert, animated: true, completion: nil)

}
如果appUsers.count<1{
//创建警报
let alert=UIAlertController(标题:“未找到干扰器”,消息:“抱歉,目前没有与您的搜索首选项匹配的干扰器。请尝试调整您的搜索首选项或稍后尝试此搜索!希望您找到您要找的人!干扰愉快!”,首选样式:UIAlertControllerStyle.alert)
//添加操作(按钮)
addAction(UIAlertAction(标题:“确定”,样式:UIAlertActionStyle.Default,处理程序:nil))
//显示警报
self.presentViewController(警报、动画:true、完成:nil)
}
按行数编辑代码

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    if appUsers.count < 1 {

        // create the alert
        let alert = UIAlertController(title: "No Jammers found", message: "Sorry there are no Jammers matching your search preferences at this time. Try tweaking your search preferences or try this search later! Hope you find who you are looking for! Happy Jamming! ", preferredStyle: UIAlertControllerStyle.Alert)

        // add an action (button)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

        // show the alert
        self.presentViewController(alert, animated: true, completion: nil)

    }

    return appUsers.count
  } // no of rows
func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
如果appUsers.count<1{
//创建警报
let alert=UIAlertController(标题:“未找到干扰器”,消息:“抱歉,目前没有与您的搜索首选项匹配的干扰器。请尝试调整您的搜索首选项或稍后尝试此搜索!希望您找到您要找的人!干扰愉快!”,首选样式:UIAlertControllerStyle.alert)
//添加操作(按钮)
addAction(UIAlertAction(标题:“确定”,样式:UIAlertActionStyle.Default,处理程序:nil))
//显示警报
self.presentViewController(警报、动画:true、完成:nil)
}
返回appUsers.count
}//行数

您可能应该将此代码移出
viewDidLoad
。无论条件如何,都会显示此项的原因是,在查询返回实际用户数之前,视图加载时用户数始终小于1。如果在节中按行数执行此操作,则条件将准确反映您的实际数据

我也在那里试过,结果也是一样的。如果用户结果为空且已满,则会显示此消息?是否在获得结果后重新加载表视图?是否在视图中加载而不是在警报后加载?我已经更新了我的代码,向你展示了我如何在numberOfRows中调用它。我遗漏了什么?最后做了一个标签来显示我的文本。