2017-01-25 4 views
-4

Ich versuche eine App zu entwickeln, die ein ähnliches Aussehen wie die Bilder hat, die ich hier angehängt habe, da ich diese Idee wirklich mag.SWIFT 3: Liste mit Dropdown-Bildern/Clips

enter image description here

Nach der Auswahl eines Elements, fällt es nach unten und ein Clip beginnt

Jede Idee zu spielen, wie dies zu implementieren? Ich kann mit Tabellen und Listen arbeiten, aber ich habe keine Ahnung, wie man so etwas tatsächlich implementiert.

enter image description here

Antwort

1

Sie können dies mit mehreren Möglichkeiten erreichen

  1. lassen indexPath = NSIndexPath (forRow: YourSelectedRow, insection: 0)

    tableView.insertRowsAtIndexPaths(indexPath, withRowAnimation: .none) 
    
        insert a different row here which will be tricky to manage. 
    
  2. alle für diese Header und und Erstellen Sie nur eine Zelle unter dem ausgewählten Abschnitt.

    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 
        } 
    
  3. Erstellen Sie zwei Zellen und diese spezifische Zelle mit Animation mit ganzen Zellenabschnitt ändern

    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 
        } 
    } 
    
+1

Ich persönlich würde sagen, Option 2 ist die „richtigste“ entsprechend der Art und Weise ist es * angeblich * um zu arbeiten. –

+0

Vielen Dank! Ich werde damit experimentieren! – FreddyGump