質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.35%

Q&A

0回答

781閲覧

swiftUIでpickerの反応範囲がおかしい

suga1405

総合スコア0

0グッド

0クリップ

投稿2020/05/25 11:14

前提・実現したいこと

swiftUIでpickerを3個HStackで並べたのですが、反応範囲が幅広なのか左のPickerを回したらその右側Pickerが反応します。いい方法ないでしょうか?
ここに質問の内容を詳しく書いてください。
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。

発生している問題・エラーメッセージ

エラーメッセージ

該当のソースコード

swiftUI```ここに言語名を入力
import SwiftUI
struct ContentView: View {
let taimu = ["32:01","32:02","32:03","32:04","32:05","32:06","32:07","32:08","32:09","32:10","32:11","32:12","32:13","32:14","32:15","32:16","32:17","32:18","32:19","32:20","32:21","32:22","32:23","32:24","32:25","32:26","32:27","32:28","32:29","32:30","32:31","32:32","32:33","32:34","32:35","32:36","32:37","32:38","32:39","32:40","32:41","32:42","32:43","32:44","32:45","32:46","32:47","32:48","32:49","32:50","32:51","32:52","32:53","32:54","32:55","32:56","32:57","32:58","32:59","33:00","33:01","33:02","33:03","33:04","33:05","33:06","33:07","33:08","33:09","33:10","33:11","33:12","33:13","33:14","33:15","33:16","33:17","33:18","33:19","33:20","33:21","33:22","33:23","33:24","33:25","33:26","33:27","33:28","33:29","33:30","33:31","33:32","33:33","33:34","33:35","33:36","33:37","33:38","33:39","33:40","33:41","33:42","33:43","33:44","33:45","33:46","33:47","33:48","33:49","33:50","33:51","33:52","33:53","33:54","33:55","33:56","33:57","33:58","33:59","34:00","34:01","34:02","34:03","34:04","34:05","34:06","34:07","34:08","34:09","34:10","34:11","34:12","34:13","34:14","34:15","34:16","34:17","34:18","34:19","34:20","34:21","34:22","34:23","34:24","34:25","34:26","34:27","34:28","34:29","34:30","34:31","34:32","34:33","34:34","34:35","34:36","34:37","34:38","34:39","34:40","34:41","34:42","34:43","34:44","34:45","34:46","34:47","34:48","34:49","34:50","34:51","34:52","34:53","34:54","34:55","34:56","34:57","34:58","34:59"]
let taimu1 = ["6:01","6:02","6:03","6:04","6:05","6:06","6:07","6:08","6:09","6:10","6:11","6:12","6:13","6:14","6:15","6:16","6:17","6:18","6:19","6:20","6:21","6:22","6:23","6:24","6:25","6:26","6:27","6:28","6:29","6:30","6:31","6:32","6:33","6:34","6:35","6:36","6:37","6:38","6:39","6:40"]
let taimu2 = ["70.0","70.1","70.2","70.3","70.4","70.5","70.6","70.7","70.8","70.9","71.0","71.1","71.2","71.3","71.4","71.5","71.6","71.7","71.8","71.9"]
@State private var selected = 79
@State private var selected1 = 19
@State private var selected2 = 13
@State var theDate = Date()
@Environment(.locale) var locale:Locale
var dateformate: DateFormatter{
let df=DateFormatter()
df.locale = Locale(identifier: "ja_JP")
df.dateStyle = .short
//df.timeStyle = .short
return df
}
@State private var displayText = ["?"]
@State private var tm = ""
@State private var tm1 = ""
@State private var tm2 = ""
@State private var str = ""
@State private var tmstr = ""
@State var userDefaults = UserDefaults.standard
var body: some View {
NavigationView {
VStack {
//Group {
HStack(alignment: .top, spacing: 20.0) {

Picker(selection: $selected,label: Text("")) { ForEach(0 ..< taimu.count) { num in Text(self.taimu[num]) } } .padding(.leading, 60.0) .frame(width: 100, height: 85) .background(/*@START_MENU_TOKEN@*/Color.blue/*@END_MENU_TOKEN@*/) Picker(selection: $selected1,label: Text("")) { ForEach(0 ..< taimu1.count) { num in Text(self.taimu1[num]) } } .padding(.leading, 40.0) .frame(width: 70, height: 85) .background(/*@START_MENU_TOKEN@*/Color.yellow/*@END_MENU_TOKEN@*/) Picker(selection: $selected2,label: Text("")) { ForEach(0 ..< taimu2.count) { num in Text(self.taimu2[num]) } } .frame(width: 60, height: 85) .background(/*@START_MENU_TOKEN@*/Color.green/*@END_MENU_TOKEN@*/) } //} List { ForEach(displayText, id: .self) {displayText in Text(displayText) .id(UUID()) } .onDelete(perform: delete) .onMove(perform: move) } .padding(.leading, 0) .navigationBarItems(leading:Button("Register") { self.tm = String(self.taimu[self.selected]) self.tm1 = String(self.taimu1[self.selected1]) self.tm2 = String(self.taimu2[self.selected2]) self.str = self.dateformate.string(from:self.theDate) self.tmstr = (self.tm) + (" ") + (self.tm1) + (" ") + (self.tm2) + (" ") + (self.str) self.displayText.insert((self.tmstr),at:0) self.displayText.sort{$0<$1} self.userDefaults.set(self.displayText, forKey: "name") },trailing: EditButton()) .navigationBarTitle(Text("runRecord")) .onAppear { guard let userdefaultText = UserDefaults.standard.value(forKey: "name") as? [String] else { return } self.displayText = userdefaultText } } }

}
func delete(offsets: IndexSet) {
displayText.remove(atOffsets: offsets)
self.userDefaults.set(self.displayText, forKey: "name")
}
func move(_ from: IndexSet,_ to:Int) {
displayText.move(fromOffsets: from,toOffset: to)
self.userDefaults.set(self.displayText, forKey: "name")
}
}
ソースコード

### 試したこと ここに問題に対して試したことを記載してください。 ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

y_waiwai

2020/05/25 11:25

このままではコードが読めないので、質問を編集し、<code>ボタンを押し、出てくる’’’の枠の中にコードを貼り付けてください
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.35%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問