teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

誤字

2019/07/01 14:49

投稿

AppDvl
AppDvl

スコア58

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  #####聞きたいこと
2
- テーブルビューをmapの下に入れたくてストリートビューで”Memo”というビューにリンクさせた途端に”Thread 1: signal SIGABRT”のエラーになる、これの直し方
2
+ ストリートビューで”Memo”というビューにリンクさせた途端に”Thread 1: signal SIGABRT”のエラーになる、これの直し方
3
3
 
4
4
  ######試したこと
5
5
  1.リンクを削除してシミュレーターてテストするとエラーは起きない(空のセルが表示される)
@@ -19,7 +19,7 @@
19
19
  #####当該のコード
20
20
 
21
21
  ```ここに言語を入力
22
- //テーブルビューの設定/////////////////////////////////////////////////////////////////////////////////////////
22
+ //テーブルビューの設定////////////////////////////////////////////////////////////////////////////////////
23
23
  // ・行の数
24
24
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
25
25
 

1

コード追加

2019/07/01 14:48

投稿

AppDvl
AppDvl

スコア58

title CHANGED
File without changes
body CHANGED
@@ -37,8 +37,232 @@
37
37
  ////////////////////////////////////////////////////////////////テーブルビューの設定//
38
38
  ```
39
39
 
40
+ ![イメージ説明](a63e38f5a1685cef57bd99491ff84236.png)
41
+ ![イメージ説明](5b9651141a997fd36a49d440e71299e8.png)
42
+ ![イメージ説明](e083df8192126df90f656f32e72ce307.png)
40
43
 
44
+ #####コード全文
41
45
 
46
+ ```ここに言語を入力
47
+ //
48
+ // MemoViewController.swift
49
+ //
50
+
51
+ import UIKit
52
+ import MapKit
53
+ import CoreLocation
54
+
55
+ class MemoViewController:
56
+ UIViewController
57
+ ,UIImagePickerControllerDelegate
58
+ ,UINavigationControllerDelegate
59
+ ,CLLocationManagerDelegate
60
+ ,UITableViewDelegate{
61
+
62
+
63
+ @IBOutlet weak var mapTypeLabel: UILabel!
64
+ @IBOutlet weak var saveButton: UIBarButtonItem!
65
+ var locationManager:CLLocationManager!
66
+ var memo: String?//saveボタン用
67
+ @IBOutlet weak var memoTextField: UITextField!
68
+ @IBOutlet weak var map: MKMapView!
69
+ @IBOutlet weak var latiudeLabel: UILabel!
70
+ @IBOutlet weak var longitudeLabel: UILabel!
71
+ @IBOutlet weak var horizontalLabel: UILabel!
72
+ @IBOutlet weak var verticalLabel: UILabel!
73
+ @IBOutlet weak var measureButton: UIButton!
74
+ var coordinates = ["130.1111","33.1111","130.2222","33.2222"]
75
+ let width = UIScreen.main.bounds.size.width//画面の幅
76
+ let height = UIScreen.main.bounds.size.height//画面の高さ
77
+
78
+ var cnt : Int = 0 //表示領域を指定:はじめの1回だけ現在地をセンターにするためif cntを設置
79
+ @IBOutlet var coordinateCollection: [UICollectionView]!
80
+
81
+ @IBAction func measureButton(_ sender: Any) {
82
+ print("開始")
83
+ }
84
+ // 画面の切替
85
+ @objc func mapViewTypeBtnThouchDown(_ sender: Any) {
86
+ switch map.mapType {
87
+ case .satelliteFlyover: // 地図よりもデータを強調○
88
+ map.mapType = .standard
89
+ mapTypeLabel.text = "standard"
90
+ mapTypeLabel.frame = CGRect(x:10, y: 130, width:90, height:30)
91
+ print("standard")
92
+ break
93
+ case .standard: // 3D航空写真☓
94
+ map.mapType = .satelliteFlyover
95
+ mapTypeLabel.text = "3D"
96
+ mapTypeLabel.frame = CGRect(x:10, y: 130, width:33, height:30)
97
+ print("satelliteFlyover")
98
+ break
99
+
100
+ @unknown default:
101
+ break
102
+ }
103
+ }
104
+
105
+ override func viewDidLoad() {
106
+ super.viewDidLoad()
107
+ //テーブルビューの設定/////////////////////////////////
108
+ // ・行の数
109
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
110
+
111
+ return coordinates.count
112
+ }
113
+
114
+ // ・セルのスタイル、何を表示するか決める
115
+ func tableView(tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
116
+ let coordinatesCell = UITableViewCell(style: UITableViewCell.CellStyle.default , reuseIdentifier: "cds")
117
+ coordinatesCell.textLabel?.text = coordinates[indexPath.row]
118
+ return coordinatesCell
119
+ }
120
+
121
+
122
+ ////////////////////テーブルビューの設定//
123
+
124
+ horizontalLabel.frame = CGRect(x:10, y: 165, width:200, height:30)
125
+ verticalLabel.frame = CGRect(x:10, y: 165, width:200, height:30)
126
+ latiudeLabel.frame = CGRect(x:10, y: 165, width:200, height:30)
127
+ longitudeLabel.frame = CGRect(x:map.frame.origin.x + map.frame.size.width,
128
+ y: map.frame.origin.y + map.frame.size.height, width:300, height:30)
129
+
130
+
131
+
132
+
133
+ locationManager = CLLocationManager()
134
+ locationManager.desiredAccuracy = kCLLocationAccuracyBest //最高精度
135
+
136
+ locationManager.requestAlwaysAuthorization()
137
+ locationManager.delegate = self // CLLocationManagerDelegat
138
+ locationManager.startUpdatingLocation()//観測開始
139
+
140
+
141
+
142
+ self.navigationItem.title = "Edit Memo"
143
+ if let memo = self.memo{
144
+ self.memoTextField.text = memo
145
+ }
146
+ self.updateSaveButtonState()
147
+ // 地図の設定〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
148
+
149
+ map.mapType = MKMapType.satelliteFlyover
150
+ map.userTrackingMode = .follow
151
+ var mapViewType: UIButton!
152
+ mapViewType = UIButton(type: UIButton.ButtonType.detailDisclosure)
153
+ /////////////
154
+ mapViewType.frame = CGRect(x:10, y: 165, width:33, height:30)
155
+
156
+ mapViewType.layer.backgroundColor = UIColor(white: 1, alpha: 0.65).cgColor
157
+ mapViewType.layer.borderWidth = 0.5
158
+ mapViewType.layer.borderColor = UIColor.blue.cgColor
159
+ self.view.addSubview(mapViewType)
160
+
161
+
162
+ /////////////
163
+ mapTypeLabel.frame = CGRect(x:10, y: 130 , width:33, height:30)
164
+ mapTypeLabel.layer.backgroundColor = UIColor(white: 1, alpha: 0.8).cgColor
165
+ mapTypeLabel.layer.borderWidth = 0.5
166
+ mapTypeLabel.layer.borderColor = UIColor.blue.cgColor
167
+ self.view.addSubview(mapTypeLabel)
168
+ mapTypeLabel.text = "3D"
169
+ // 地図の表示タイプを切り替える関数
170
+ mapViewType.addTarget(self, action: #selector(mapViewTypeBtnThouchDown(_:)), for: .touchDown)
171
+
172
+ }
173
+ private func updateSaveButtonState(){
174
+ let memo = self.memoTextField.text ?? ""
175
+ self.saveButton.isEnabled = !memo.isEmpty
176
+ }
177
+ @IBAction func memoTextFieldChanged(_ sender: Any) {
178
+ updateSaveButtonState()
179
+ }
180
+
181
+ @IBAction func cancel(_ sender: Any) {
182
+
183
+ if self.presentingViewController is
184
+ UINavigationController {
185
+ self.dismiss(animated: true, completion: nil)
186
+ } else {
187
+ self.navigationController?.popViewController(animated: true)
188
+ }
189
+ }
190
+
191
+ override func didReceiveMemoryWarning() {
192
+ super.didReceiveMemoryWarning()
193
+ }
194
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
195
+ guard let button = sender as? UIBarButtonItem, button === self.saveButton else {
196
+ return
197
+ }
198
+ self.memo = self.memoTextField.text ?? ""
199
+ }
200
+ }
201
+
202
+ //位置情報の許可=============
203
+ extension MemoViewController {
204
+ func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
205
+ switch status {
206
+ case .notDetermined:
207
+ print("ユーザーはこのアプリケーションに関してまだ選択を行っていません")
208
+ locationManager.requestAlwaysAuthorization()
209
+ break
210
+ case .denied:
211
+ print("ローケーションサービスの設定が「無効」になっています (ユーザーによって、明示的に拒否されています)")
212
+
213
+ let alert : UIAlertController = UIAlertController(title: "測定を続けるには", message: "設定 > プライバシー > 位置情報サービス で、位置情報サービスの利用を許可して下さい。", preferredStyle: .alert)
214
+ let okAction = UIAlertAction(title:"OK", style: .default,handler: nil)
215
+ alert.addAction(okAction)
42
- ![イメージ説明](a63e38f5a1685cef57bd99491ff84236.png)
216
+ present(alert,animated: true,completion: nil)
217
+
218
+ break
219
+ case .restricted:
220
+ print("このアプリケーションは位置情報サービスを使用できません(ユーザによって拒否されたわけではありません)")
221
+
222
+ break
223
+ case .authorizedAlways:
224
+ print("常時、位置情報の取得が許可されています。")
225
+
226
+ break
227
+ case .authorizedWhenInUse:
228
+ print("起動時のみ、位置情報の取得が許可されています。")
229
+
43
- ![イメージ説明](5b9651141a997fd36a49d440e71299e8.png)
230
+ locationManager.requestAlwaysAuthorization()
231
+ break
232
+ @unknown default:
233
+ break
234
+ }
235
+ }
236
+ //=====================位置情報の許可
237
+
238
+
239
+ func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {//GPSが更新すると呼ばれる
240
+ let location : CLLocation = locations[0]
44
- ![イメージ説明](e083df8192126df90f656f32e72ce307.png)
241
+ let currentlocation = location.coordinate
242
+
243
+
244
+ if cnt == 0{
245
+ let reg : MKCoordinateRegion = MKCoordinateRegion(center: currentlocation,latitudinalMeters: 100,longitudinalMeters: 100)
246
+ map.region = reg
247
+
248
+ let viewPoint :CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude-0.005, location.coordinate.longitude)
249
+
250
+ map.showsBuildings = true
251
+
252
+ map.isPitchEnabled = true
253
+
254
+ let cameraVR : MKMapCamera = MKMapCamera(lookingAtCenter: currentlocation, fromEyeCoordinate: viewPoint, eyeAltitude: 100)
255
+ map.camera = cameraVR
256
+ cnt = 1
257
+ }
258
+
259
+ latiudeLabel.text = String("緯度:(location.coordinate.latitude)" )
260
+ longitudeLabel.text = String("経度:(location.coordinate.longitude)")
261
+ horizontalLabel.text = String("水平精度:(location.horizontalAccuracy)")
262
+ verticalLabel.text = String("垂直精度:(location.verticalAccuracy)")
263
+
264
+ }
265
+ }
266
+
267
+
268
+ ```