Storyboard TableView with Segues to Multiple Views

前端 未结 3 1319
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 08:17

I am having an issue with designing a storyboard. I currently have an app in the app store that was designed with XIB files. I have a tableView placed on a UIViewControlle

相关标签:
3条回答
  • 2021-01-03 08:39

    The method override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) is called when an item is deselected.

    To call a method when an item is selected, change the method name to override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)

    0 讨论(0)
  • 2021-01-03 08:49

    Swift 3 Code
    Well, look at my piece of code I use to perform dynamic segue based on the type of the device type in the cell. :) Hope it helps.

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let device = Cache.DEVICELIST[indexPath.row]
        let deviceType = device.type
    
        switch deviceType {
        case "camera":
            self.performSegue(withIdentifier: "DashCellToCamera", sender: self)
    
        case "gateway" :
            self.performSegue(withIdentifier: "DashCellToGateway", sender: self)
    
        case "tracker" :
            self.performSegue(withIdentifier: "DashCellToTracker", sender: self)
    
        case "panicbutton" :
            self.performSegue(withIdentifier: "DashCellToPanicButton", sender: self)
    
        default:
            break
            //do nothing just ignore this
        }
    }
    
    0 讨论(0)
  • 2021-01-03 08:56

    I used a combination of the comment by Allen. Initially I wasn't able to create the segues I needed. I created a navigation controller that uses my own view controller that holds a tableview. Then I created the associated cells for the prototype cells and switched them to a static cell. I only have a limited amount, 3 at the time. This allowed me to created the segues to the appropriate views in the storyboard. Then I changed the cells back to prototype cells and it maintained the connection to the segues. All that is left was creating the associated switch statement in the table view to go to the correct segue. Just make sure you name your segues with the identifiers listed in your code.

       func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath) {
        //Add cases here to move to different segues
        switch indexPath.row{
        case 0: self.performSegueWithIdentifier("courses", sender: self);
        break;
        case 1: self.performSegueWithIdentifier("finals", sender: self);
        break;
        case 2: self.performSegueWithIdentifier("academic", sender: self);
        break;
        default:
        break
        }
    
    }
    

    0 讨论(0)
提交回复
热议问题