문제

내가 직면하는 오류 메시지를 표시합니다.

"UIStoryboardSegue does not have a member named 'identifier'"

여기에는 코드는 오류를 일으키는

if (segue.identifier == "Load View") {
    // pass data to next view
}

에 Obj C-그것은 잘 사용하여 다음과 같다:

if ([segue.identifier isEqualToString:@"Load View"]) {
   // pass data to next view
}

무엇이 잘못된 것입니까?

도움이 되었습니까?

해결책

이 때문일 것으로 보인 문제에 UITableViewController 서브 클래스는 템플릿입니다.그것은 버전 prepareForSegue 는 방법을 필요 당신을 풀 segue.

현재 prepareForSegue 기능:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "Load View") {
        // pass data to next view
    }
}

이 버전이 암시적으로 풀어냅 매개변수,그래서 당신은 잘해야합니다.

다른 팁

swift 4, swift 3

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "MySegueId" {
        if let nextViewController = segue.destination as? NextViewController {
                nextViewController.valueOfxyz = "XYZ" //Or pass any values
                nextViewController.valueOf123 = 123
        }
    }
}
.

나는 문제가 그것을 사용해야한다고 생각한다!unbundly 식별자

나는

가있다
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
        if segue!.identifier == "Details" {
            let viewController:ViewController = segue!.destinationViewController as ViewController
            let indexPath = self.tableView.indexPathForSelectedRow()
            viewController.pinCode = self.exams[indexPath.row]

        }

    }
.

나의 이해는 그 일이 없다는 것입니다!당신은 진실 또는 거짓된 값을 얻습니다

스위프트 2.3, Swift3 및 Swift4 :

DidSelectRowAtindexpath에서 Segue 수행

예 :

   self.performSegue(withIdentifier: "uiView", sender: self)
.

대상 세그리를 잡고 값을 전달하는 PrepeyForsegue 함수를 만듭니다.

ex :

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

       if segue.identifier == "uiView"{

        let destView = segue.destination as! WebViewController
        let indexpath = self.newsTableView.indexPathForSelectedRow
        let indexurl = tableDatalist[(indexpath?.row)!].link
        destView.UrlRec = indexurl

        //let url =

    }
    }
.

대상 ViewController에서 URLREC라는 변수를 만들어야합니다

Swift 1.2

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
            if (segue.identifier == "ShowDeal") {

                if let viewController: DealLandingViewController = segue.destinationViewController as? DealLandingViewController {
                    viewController.dealEntry = deal
                }

            }
     }

Prepare for Segue in Swift 4.2 and Swift 5.

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "OrderVC") {
        // pass data to next view
        let viewController = segue.destination as? MyOrderDetailsVC
        viewController!.OrderData = self.MyorderArray[selectedIndex]


    }
}

How to Call segue On specific Event(Like Button Click etc):

performSegue(withIdentifier: "OrderVC", sender: self)

this is one of the ways you can use this function, it is when you want access a variable of another class and change the output based on that variable.

   override func prepare(for segue: UIStoryboardSegue, sender: Any?)  {
        let something = segue.destination as! someViewController
       something.aVariable = anotherVariable
   }

Provided you aren't using the same destination view controller with different identifiers, the code can be more concise than the other solutions (and avoids the as! in some of the other answers):

override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
    if let myViewController = segue.destinationController as? MyViewController { 
        // Set up the VC
    }
}

Change the segue identifier in the right panel in the section with an id. icon to match the string you used in your conditional.

override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
        if(segue!.identifier){
            var name = segue!.identifier;
            if (name.compare("Load View") == 0){

            }
        }
    }

You can't compare the the identifier with == you have to use the compare() method

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top