小编Sal*_*h Ç的帖子

不调用UIAlertAction处理程序

我有一个UITableView,在委托(视图控制器)中,我实现了该功能

    tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
Run Code Online (Sandbox Code Playgroud)

然后我测试编辑风格

    if editingStyle == UITableViewCellEditingStyle.Delete {
        // do deleting stuff here
    }
Run Code Online (Sandbox Code Playgroud)

作为删除的一部分,我要求用户确认,如果他们选择"是",则与该行相关的项目将被删除,如果他们选择否,则重置编辑样式.

  var alert = UIAlertController(title: "Delete Item", message: "Are you sure you want to delete the selected item?", preferredStyle: UIAlertControllerStyle.Alert)

  //delete
  alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Destructive, handler: { (action: UIAlertAction!) -> Void in
      println("Yes action was selected")
      //delete my object and remove from the table
  }))

  //cancel
  alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (action: UIAlertAction!) -> Void in
      //reset editing …
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller uialertaction

6
推荐指数
3
解决办法
1864
查看次数

在Swift中将AnyObject添加到NSMutableArray

我只是想做Tableview搜索.我正在NSPredicate用于搜索.

每个教程都会给出这个代码行:

let resultPredicate = NSPredicate(format: "SELF contains[c] %@", searchText)
self.nameArray = self.nameArray.filteredArrayUsingPredicate(resultPredicate)
Run Code Online (Sandbox Code Playgroud)

但在第二行Xcode中说: Cannot assign a value of type '[AnyObject]' to a value of type 'NSMutableArray'

我试图转换,但这次xcode创建零值.我的两个阵列都是NSMutableArray.任何建议?

编辑

我的手机代码:

let cell:ItemsTVCell = tableView.dequeueReusableCellWithIdentifier("CELL") as! ItemsTVCell

    if tableView == self.searchDisplayController?.searchResultsTableView {
        cell.itemNameLabel.text = filteredArray[indexPath.row] as? String
    } else {
        cell.itemNameLabel.text = nameArray[indexPath.row] as? String
    }

    return cell
Run Code Online (Sandbox Code Playgroud)

uitableview nspredicate ios swift

0
推荐指数
1
解决办法
1153
查看次数