質問編集履歴
3
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,4 +17,63 @@
|
|
17
17
|
0. [History]ボタン 1 → 3 → 2
|
18
18
|
|
19
19
|
**コード等は下記のリポジトリにあげています。**
|
20
|
-
https://github.com/haruka22/project
|
20
|
+
https://github.com/haruka22/project
|
21
|
+
|
22
|
+
### 追記
|
23
|
+
遷移先のtableViewにデータが反映されない
|
24
|
+
```HistoryViewController.swift
|
25
|
+
import UIKit
|
26
|
+
|
27
|
+
class HistoryViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
|
28
|
+
|
29
|
+
@IBOutlet weak var HistorytableView: UITableView!
|
30
|
+
|
31
|
+
|
32
|
+
var datetime = UILabel()//var datetime: UILabel! /オプショナル型はなるべく使わない
|
33
|
+
var nameitem = UILabel()
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
// ボタンを用意
|
38
|
+
var addBtn: UIBarButtonItem!
|
39
|
+
|
40
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
41
|
+
return 0
|
42
|
+
}
|
43
|
+
|
44
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
45
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath)
|
46
|
+
cell.textLabel?.text = datetime.text
|
47
|
+
|
48
|
+
return cell
|
49
|
+
}
|
50
|
+
|
51
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
52
|
+
//セルの選択解除
|
53
|
+
tableView.deselectRow(at: indexPath, animated: true)
|
54
|
+
|
55
|
+
//ここに遷移処理を書く
|
56
|
+
self.present(ViewController(), animated: true, completion: nil)
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
override func viewDidLoad() {
|
62
|
+
super.viewDidLoad()
|
63
|
+
|
64
|
+
HistorytableView.delegate = self
|
65
|
+
HistorytableView.dataSource = self
|
66
|
+
HistorytableView.backgroundColor = UIColor.lightGray
|
67
|
+
self.navigationItem.title = "データベース"
|
68
|
+
HistorytableView.reloadData()
|
69
|
+
}
|
70
|
+
|
71
|
+
func onClick() {
|
72
|
+
print("ボタンがおされました")
|
73
|
+
let second = ViewController()
|
74
|
+
present(second, animated: true, completion: nil)
|
75
|
+
|
76
|
+
}
|
77
|
+
|
78
|
+
}
|
79
|
+
```
|
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,90 +1,20 @@
|
|
1
|
+
### やりたいこと
|
1
|
-
|
2
|
+
コードでの画面遷移を実現したい。(少し複雑な)
|
2
|
-
|
3
|
+
ホーム画面で入力したしたデータを他のsceneに渡したい。
|
3
4
|
|
4
|
-
**
|
5
|
+
**出来ていること**
|
5
|
-
|
6
|
+
入力したデータは他のscnenには渡せている。
|
6
|
-
|
7
|
+
基本的な画面遷移は出来ている。
|
7
8
|
|
8
|
-
### やりたい事
|
9
|
-
|
9
|
+
**困っていること**
|
10
|
-
|
10
|
+
他のsceneに渡したデータをtableViewに反映されない。
|
11
|
-
そしてデータの遷移先(tableView scene)は2018/5/28や日記のタイトルとと言った目次のViewになります。
|
12
|
-
やりたい事としては、遷移の回数を省略するためにデータの遷移先を経由しないでホーム画面(viewCotroller scene)からlabel scnenに遷移させたいです。その際に、ホーム画面をタップした時にアラートで入力した中身が(データの遷移先のタイトルになり、日付は遷移した時の日付になります。)
|
13
|
-
やりたい事としては、カッコの部分を遷移せずに自動的に行いたいです。
|
14
|
-
そして、日記帳なので振り返りたい時に以下の流れにしたいです。
|
15
|
-
|
11
|
+
下記の2.[History]ボタンからの遷移がうまく出来ずに困っている。(tableviewにデータを渡せれてないのが原因だと思われる。)
|
16
12
|
|
13
|
+
- 1.ホーム画面scene
|
14
|
+
- 2.内容scene
|
15
|
+
- 3.内容を管理するscene
|
16
|
+
0. [start]ボタン 1 → 2
|
17
|
+
0. [History]ボタン 1 → 3 → 2
|
18
|
+
|
17
|
-
**
|
19
|
+
**コード等は下記のリポジトリにあげています。**
|
18
|
-
データを渡すことに関しては以前の質問などを参考にし稚拙なコードながら出来ていると思います。
|
19
|
-
困っている事はやりたいことの中に書いていますが遷移全般が全く分からず、ポケットリファレンスやqiita等でも調べてみましたがそのような記事を見つけることができませんでした。
|
20
|
-
下記のコードで遷移前にアラートを呼び出そうとしているのですが遷移後にアラートが呼び出される形になってしまい入力してからさらに遷移してしまう。
|
21
|
-
```swift
|
22
|
-
@IBAction func seguebtr1(_ sender: Any) {
|
23
|
-
//ここではViewControllerに飛ぶ遷移についてと遷移先のnavigationbarのtitleの変更について
|
24
|
-
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
25
|
-
|
26
|
-
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
27
|
-
(action:UIAlertAction!) -> Void in
|
28
|
-
|
29
|
-
if let textFields = alert.textFields {
|
30
|
-
|
31
|
-
for textField in textFields {
|
32
|
-
if let text = textField.text {
|
33
|
-
print(textField.text!)
|
34
|
-
|
20
|
+
https://github.com/haruka22/project
|
35
|
-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
36
|
-
self.performSegue(withIdentifier: "ViewControllersegue", sender: text)//元々nilだった
|
37
|
-
}
|
38
|
-
|
39
|
-
}
|
40
|
-
}
|
41
|
-
}
|
42
|
-
})
|
43
|
-
alert.addAction(okAction)
|
44
|
-
|
45
|
-
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
46
|
-
alert.addAction(cancelAction)
|
47
|
-
|
48
|
-
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
49
|
-
textField.placeholder = "テキスト"
|
50
|
-
})
|
51
|
-
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
52
|
-
// アラートを画面に表示
|
53
|
-
self.present(alert, animated: true, completion: nil)
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
@IBAction func seguebtr2(_ sender: Any) {
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
64
|
-
if segue.identifier == "ViewControllersegue",
|
65
|
-
let nextView: label = segue.destination as? label,
|
66
|
-
let text = sender as? String {
|
67
|
-
nextView.titleName = text
|
68
|
-
}
|
69
|
-
|
70
|
-
if segue.identifier == "ViewControllersegue2",
|
71
|
-
let nextView2: tableView = segue.destination as? tableView,
|
72
|
-
let text = sender as? String {
|
73
|
-
nextView2.titleName2 = text
|
74
|
-
|
75
|
-
//subtitle 現在日時を取得
|
76
|
-
let now = NSDate() // 現在日時の取得
|
77
|
-
|
78
|
-
let dateFormatter = DateFormatter()
|
79
|
-
dateFormatter.locale = NSLocale(localeIdentifier: "en_US") as Locale? // ロケールの設定
|
80
|
-
dateFormatter.dateFormat = "yyyy年MM月dd日 HH:mm"//:ss" // 日付フォーマットの設定
|
81
|
-
|
82
|
-
let dateString = dateFormatter.string(from: now as Date)
|
83
|
-
|
84
|
-
nextView2.timeitem = dateString
|
85
|
-
print(dateString) // -> 2014/06/25 02:13:18
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
}
|
90
|
-
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,4 +16,75 @@
|
|
16
16
|
|
17
17
|
**出来ている事と困っている事**
|
18
18
|
データを渡すことに関しては以前の質問などを参考にし稚拙なコードながら出来ていると思います。
|
19
|
-
困っている事はやりたいことの中に書いていますが遷移全般が全く分からず、ポケットリファレンスやqiita等でも調べてみましたがそのような記事を見つけることができませんでした。
|
19
|
+
困っている事はやりたいことの中に書いていますが遷移全般が全く分からず、ポケットリファレンスやqiita等でも調べてみましたがそのような記事を見つけることができませんでした。
|
20
|
+
下記のコードで遷移前にアラートを呼び出そうとしているのですが遷移後にアラートが呼び出される形になってしまい入力してからさらに遷移してしまう。
|
21
|
+
```swift
|
22
|
+
@IBAction func seguebtr1(_ sender: Any) {
|
23
|
+
//ここではViewControllerに飛ぶ遷移についてと遷移先のnavigationbarのtitleの変更について
|
24
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
25
|
+
|
26
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
27
|
+
(action:UIAlertAction!) -> Void in
|
28
|
+
|
29
|
+
if let textFields = alert.textFields {
|
30
|
+
|
31
|
+
for textField in textFields {
|
32
|
+
if let text = textField.text {
|
33
|
+
print(textField.text!)
|
34
|
+
//遅延に関するコード // セグエにtextを渡す
|
35
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
36
|
+
self.performSegue(withIdentifier: "ViewControllersegue", sender: text)//元々nilだった
|
37
|
+
}
|
38
|
+
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
})
|
43
|
+
alert.addAction(okAction)
|
44
|
+
|
45
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
46
|
+
alert.addAction(cancelAction)
|
47
|
+
|
48
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
49
|
+
textField.placeholder = "テキスト"
|
50
|
+
})
|
51
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
52
|
+
// アラートを画面に表示
|
53
|
+
self.present(alert, animated: true, completion: nil)
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
@IBAction func seguebtr2(_ sender: Any) {
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
64
|
+
if segue.identifier == "ViewControllersegue",
|
65
|
+
let nextView: label = segue.destination as? label,
|
66
|
+
let text = sender as? String {
|
67
|
+
nextView.titleName = text
|
68
|
+
}
|
69
|
+
|
70
|
+
if segue.identifier == "ViewControllersegue2",
|
71
|
+
let nextView2: tableView = segue.destination as? tableView,
|
72
|
+
let text = sender as? String {
|
73
|
+
nextView2.titleName2 = text
|
74
|
+
|
75
|
+
//subtitle 現在日時を取得
|
76
|
+
let now = NSDate() // 現在日時の取得
|
77
|
+
|
78
|
+
let dateFormatter = DateFormatter()
|
79
|
+
dateFormatter.locale = NSLocale(localeIdentifier: "en_US") as Locale? // ロケールの設定
|
80
|
+
dateFormatter.dateFormat = "yyyy年MM月dd日 HH:mm"//:ss" // 日付フォーマットの設定
|
81
|
+
|
82
|
+
let dateString = dateFormatter.string(from: now as Date)
|
83
|
+
|
84
|
+
nextView2.timeitem = dateString
|
85
|
+
print(dateString) // -> 2014/06/25 02:13:18
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
}
|
90
|
+
```
|