Swift에서 Segue 준비
오류 메시지가 나타납니다.
"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
}
}
이 버전은 매개 변수를 암시 적으로 풀기 때문에 괜찮습니다.
스위프트 4, 스위프트 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
}
}
}
문제는! 식별자 번들 해제
나는 가지고있다
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]
}
}
내 이해는! 당신은 참 또는 거짓 값을 얻습니다
Swift 2.3, swift3 및 swift4의 경우 :
didSelectRowAtindexPath에서 수행 Segue 만들기
예 :
self.performSegue(withIdentifier: "uiView", sender: self)
그 후 목적지 segue를 포착하고 값을 전달하는 prepareforSegue 함수를 작성하십시오.
전의:
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 =
}
}
You need to create a variable named UrlRec in Destination ViewController
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
참고URL : https://stackoverflow.com/questions/24040692/prepare-for-segue-in-swift
'Development Tip' 카테고리의 다른 글
SQL Server의 VARCHAR에서 숫자가 아닌 문자를 제거하는 가장 빠른 방법 (0) | 2020.12.02 |
---|---|
Eclipse : Android SDK를 사용할 수 없으며 ADT가 오래되었다고 잘못 주장합니다. (0) | 2020.12.02 |
Laravel에서 키가 아닌 열 필드에 대한 고유 값을 얻는 방법은 무엇입니까? (0) | 2020.12.02 |
애플리케이션을 호스팅하는 dotnet.exe의 프로세스 ID를 확인하는 중에 오류가 발생했습니다. (0) | 2020.12.02 |
asp.net에서 데이터 테이블 열의 합계를 계산하는 방법은 무엇입니까? (0) | 2020.12.02 |