Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
SWIFT 3:带有下拉图片/剪辑的列表_Swift_List_Dropdown - Fatal编程技术网

SWIFT 3:带有下拉图片/剪辑的列表

SWIFT 3:带有下拉图片/剪辑的列表,swift,list,dropdown,Swift,List,Dropdown,我正在尝试开发一个应用程序,它的外观与我在这里附上的图片相似,因为我真的很喜欢这个想法 选择一个项目后,它会下降并开始播放剪辑 你知道如何实施吗?我可以使用表和列表,但我不知道如何实际实现这样的东西 您可以通过多种方式实现这一点 让indexPath=NSIndexPath(forRow:YourSelectedRow,第0节) 创建所有这些标题,并在所选节下仅创建一个单元格 var selectedSection = -1 func tableView(tableView: U

我正在尝试开发一个应用程序,它的外观与我在这里附上的图片相似,因为我真的很喜欢这个想法

选择一个项目后,它会下降并开始播放剪辑

你知道如何实施吗?我可以使用表和列表,但我不知道如何实际实现这样的东西


您可以通过多种方式实现这一点

  • 让indexPath=NSIndexPath(forRow:YourSelectedRow,第0节)

  • 创建所有这些标题,并在所选节下仅创建一个单元格

     var selectedSection =  -1 
    
      func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
       {
             let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 50)
             let button = UIButton(frame: view.frame)
             button.tag = section
             button.addTarget(self, action: #selector(selectExercise(_:), forControlEvents: UIControlEvents.TouchUpInside)
       }
    
      func numberOfSectionsInTableView(tableView: UITableView) -> Int
       {
            return 5 
       }
    
     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
        {
            if section == selectedSection
             {
                return 1
          }
         else
            {
                return 0
         }
        }
    
          func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
         {
                    let cell = tableView.dequeueReusableCellWithIdentifier(“YourDetailCell”, forIndexPath: indexPath) as! YourDetailCell
            return cell
      }
    
     fun selectExercise(sender:UIButton)
        {
        selectedSection = sender.tag 
        }
    
  • 创建两个单元,并使用动画将该特定单元与整个单元部分一起更改

    var selectedRow =  -1 
    
      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
     {
            if selectedRow == -1
         {
                 selectedRow = indexPath.row 
                 tblConfirmedServices.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Bottom)
          }
            else
         {
                selectedRow = - 1 
             tblConfirmedServices.reloadRowsAtIndexPaths([indexPathPre], withRowAnimation: .Top)
        }       
      }
    
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
       {
        if selectedRow = indexPath.row
         {
                    let cell = tableView.dequeueReusableCellWithIdentifier(“YourDetailCell”, forIndexPath: indexPath) as! YourDetailCell
                return cell
         }
         else
         {
                let cell = tableView.dequeueReusableCellWithIdentifier(“YourCell”, forIndexPath: indexPath) as! YourCell
                return cell
       }
    }
    

  • 就我个人而言,我想说,根据它的工作方式,选项2是“最正确的”。非常感谢!我要用这个做实验!
    var selectedRow =  -1 
    
      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
     {
            if selectedRow == -1
         {
                 selectedRow = indexPath.row 
                 tblConfirmedServices.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Bottom)
          }
            else
         {
                selectedRow = - 1 
             tblConfirmedServices.reloadRowsAtIndexPaths([indexPathPre], withRowAnimation: .Top)
        }       
      }
    
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
       {
        if selectedRow = indexPath.row
         {
                    let cell = tableView.dequeueReusableCellWithIdentifier(“YourDetailCell”, forIndexPath: indexPath) as! YourDetailCell
                return cell
         }
         else
         {
                let cell = tableView.dequeueReusableCellWithIdentifier(“YourCell”, forIndexPath: indexPath) as! YourCell
                return cell
       }
    }