한 가지보기에 한 가지만 입력하면 다른보기에 표시되는 응용 프로그램이 있습니다. 이 정보를 데이터베이스로 전송 한 다음 다른보기에서 검색하거나이 정보를 직접 전달할 수있는 방법이 있습니까?다른보기 컨트롤러의 정보를 전달하는 iOS
답변
에 또 다른 segues있는 하나의 ViewController에서 정보를 전송하는 가장 좋은 방법을 살펴 있습니다.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "yourIdentifierInStoryboard") {
let yourNextViewController = (segue.destinationViewController as yourNextViewControllerClass)
yourNextViewController.value = yourValue
을 그리고 당신의 yourNextViewController 클래스 :
이 같이 사용할 수 있습니다.
class yourNextViewControllerClass {
var value:Int! // or whatever
또한 프로그램이 호출 할 수 있습니다 :
self.performSegueWithIdentifier("yourIdentifierInStoryboard", sender: self)
값을 설정하여 DestinationViewController에서 다시 차 (처음으로)의 ViewController
1에 프로토콜을 구현, 예를 들어 protocol.swift라는 파일을 작성하십시오.
2
protocol changeUserValueDelegate {
func changeUser(toValue:Bool)
}
는 두 번째보기 class yourNextViewControllerClass {
var delegate:changeUserValueDelegate?
3. 부하에 위임을 설정 (prepareForSegue)
if(segue.identifier == "yourIdentifierInStoryboard") {
var yourNextViewController = (segue.destinationViewController as yourNextViewControllerClass)
yourNextViewController.delegate = self
4. 추가 기능에 위임을 설정 FirstViewController에
func changeUser(toValue:Bool) {
self.currentUserValue = toValue
}
5. 호출하여 SecondViewController에서이 기능을
delegate?.changeUser(true)
6.는
class FirstViewController: UIViewController, ChangeUserValueDelegate {
이 답변을 주셔서 감사합니다.여기에 게시 할 수있는 자습서에 대한 링크가 있습니까? – tryingtolearn
이것은 다른 질문에 대한 저의 답이었습니다. 하지만 자습서가 많이 있습니다 : https://www.raywenderlich.com/113394/storyboards-tutorial-in-ios-9-part-2 – derdida
당신은 당신이 줄 수있는 프로그래밍 방식으로 그 일을하는 경우 FirstViewController의 대리자를 설정 목적지보기 컨트롤러가 스토리 보드에있는 식별자이고 Viewcontroller로 이동할 때이 ID를 사용하여이 뷰 컨트롤러를 가져옵니다. entifier 두 번째 뷰 컨트롤러에 속성을 추가하면
을 쓴 텍스트를 얻을 수예 :
let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let secondViewController = storyBoard.instantiateViewControllerWithIdentifier("secondViewControllerIdentifier") as! UserBasicInfoViewController
secondViewController.Text = self.textField.text
self.navigationController?.pushViewController(userProfile, animated: true)
또는
팁을위한
@EricAya 감사
! 나는 그런 일이 일어나지 않도록 할 것입니다. – tryingtolearn