스토리보드에서 화면 이동 배우기
입문
이 자료는 슈크
はじめてのiOSアプリ開発② - 基本操作を覚えよう
의 제5회(첫 번째 iOS 응용프로그램 개발 - Twitter의 타임라인 기반 제작(사용자 동작 활동) 내용의 서경이다.수업을 안 본 사람이라도 가능한 한 분명하게 써야 한다.
전제 조건
몇 시간의 수업을 통해 트위터 앱을 만들다.
지난번 강의에서는 UI를 만드는 도구인 스토리보드의 사용법의 기본을 배웠습니다.
지난번이니까 계속 저번 보도 읽는 게 좋아요.
오늘 할 일
트위터 응용 프로그램의 로그인 논리를 만듭니다.

이런 놈이야.
1. UI 준비
새 탐색 컨트롤러를 추가합니다.
Navigation Controller
을 추가하면 Navigation Controller
와 연결된 Root View Controller
두 뷰가 추가됩니다.
もともとあったViewController
에 단추를 추가하고 텍스트를 로그인으로 변경합니다.
시작 시 보기 변경
4차에서는 TableView 한쪽에서만 작동하기 때문에 시작하는 화살표가 TableView를 가리키지만 이번에는
Navigation Controller
를 가리킨다.
관계 변경
Navigation Controller
부터 Root View Controller
까지의 관계를 もともとあったViewController
로 변경합니다.Navigation Controller
를 클릭하면 검사기 영역에 표시된 태그
Triggered Segues
섹션의 선을 もともとあったViewController
로 드래그합니다.
2. ViewController.swift에 프로그램 쓰기
복제품을 사용할 수 있습니다.설명은 교실에서.
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var loginButton: UIButton!
var accountsList:[Dictionary<String,String>]?
var tweets:[Dictionary<String, AnyObject>]?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
accountsList = [["name":"Hiro"], ["name":"Account BBB"], ["name":"Account CCC"]]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func tappedLoginButton(sender: AnyObject) {
var accountSelectionSheet = UIAlertController()
accountSelectionSheet.title = "Select Account"
let selectAction = { (var action: UIAlertAction!) -> Void in
self.performSegueWithIdentifier("showTimelineViewController", sender: nil)
}
if let accounts:[Dictionary<String, String>] = accountsList{
for account in accounts {
let action = UIAlertAction(title: account["name"]!, style: .Default, handler: selectAction)
accountSelectionSheet.addAction(action)
}
}
let CanceledAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
accountSelectionSheet.addAction(CanceledAction)
self.presentViewController(accountSelectionSheet, animated: true, completion: nil)
}
}
3. 사건과 처리를 결합
ViewController.swift에서 설명한
tappedLoginButton()
함수는 로그인 단추를 누르면 실행됩니다.Storyboard와 소스 코드를 모두 확인하십시오.
제어키를 누르는 동시에 로그인 단추를 선택하고 원본 코드의
tappedLoginButton()
근처로 드래그하면 연결할 수 있습니다.
도중에 확인을 거치다
여기까지가 이런 느낌이야.

4. 로그인에서 Timeline으로 표시
기존 ViewController 및 TimelineViewController 연결
もともあったViewController
를 클릭하고 검사기 영역의 manual
에서 TimelineViewController
로 드래그합니다.
Storyboard Segue 프로젝트
Identifier
를 showTimelineViewController
, Segue
를 show (e.g. Push)
로 설정합니다.
이런 느낌이 들 거예요.

실행해 봅시다
로그인 버튼 -> 사용자 선택 -> Timeline 표시 가능.

5. Tweet 세부 화면으로의 전환 만들기
Timeline 목록을 누르면 세부 화면으로 이동합니다.
새 뷰 추가
TweetDetailViewController.swift
.
스토리보드에도 뷰를 추가합니다.

추가된view의 이름은
TweetDetailViewController
입니다.
Timeline에서 Tweet 연결 상세 정보
아까와 같이
TimelineViewController
, 검사구역의manual
에서 방금 제작한TweetDetailViewController
의 드래그 앤 드롭->show를 선택합니다.
Identifier에 가입
showTweetDetailViewController
.
세부 정보 페이지에서 유사한 텍스트 설정

6. 해봐
지금까지 순조로운 상황에서 집행할 수 있는 특별한 문제는 없다.

총결산
고생하셨습니다.
Reference
이 문제에 관하여(스토리보드에서 화면 이동 배우기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/n0bisuke/items/ba9e76254c4e577cae2e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)