相关疑难解决方法(0)

如何从集合视图中删除项目?

我尝试根据用户在alert中的选择从collectionview中删除项目

我有以下代码

  func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let person = people[indexPath.item]

    let questionController = UIAlertController(title: "What u wanna do?", message: nil, preferredStyle: .Alert)
    questionController.addAction(UIAlertAction(title: "Rename person", style: .Default, handler: {

        (action:UIAlertAction!) -> Void in

        let ac = UIAlertController(title: "Rename person", message: nil, preferredStyle: .Alert)
        ac.addTextFieldWithConfigurationHandler(nil)

        ac.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
        ac.addAction(UIAlertAction(title: "OK", style: .Default) { [unowned self, ac] _ in
            let newName = ac.textFields![0] as! UITextField
            person.name = newName.text

            self.collectionView.reloadData() })

        self.presentViewController(ac, animated: true, completion: nil)

    })) …
Run Code Online (Sandbox Code Playgroud)

uicollectionview swift

13
推荐指数
1
解决办法
2万
查看次数

如何在Swift中向Collection View Cell添加删除按钮?

现在我有一个滚动用户名列表,使用按钮的集合视图.但我想为每一行添加重叠的删除按钮.它们需要附加到名称按钮并随之滚动.

如何将这些按钮添加到CollectionView?(另外我想跳过第一行的删除按钮,原因很明显)

用户选择屏幕

现行代码:

  //Add the cells to collection
  func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell: UsernameCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! UsernameCollectionViewCell
    cell.usernameLabel.text = userNames [indexPath.row]
    return cell
  }

  //Upon Selecting an item
  func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    if (indexPath.row == 0){
      self.performSegueWithIdentifier("newUserSegue", sender: self)
    }
    else {
      sendData(userNames[indexPath.row])
      self.dismissViewControllerAnimated(true, completion: nil)
    }

  }
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview uicollectionviewcell swift

4
推荐指数
1
解决办法
2万
查看次数