質問編集履歴

1

該当のソースコードを変更

2022/10/14 05:41

投稿

Chang1214
Chang1214

スコア1

test CHANGED
File without changes
test CHANGED
@@ -21,68 +21,139 @@
21
21
 
22
22
  ```SwiftUI
23
23
  import SwiftUI
24
+ import PhotosUI
24
25
 
25
- struct RegisterProfileView: View {
26
+ struct ProfileView: View {
26
- @State var firstName: String = ""
27
- @State var firstNameFurigana: String = ""
28
- @State var lastName: String = ""
29
- @State var lastNameFurigana: String = ""
30
- @State var company: String = ""
31
- @State var companyFurigana: String = ""
27
+ @EnvironmentObject var profileData: ProfileData
32
- //Name & Company data
33
-
34
- @State var telNumber: [String] = []
35
28
  @Environment(\.editMode) var editMode
36
-
29
+ @State var phoneNumberView: Bool = false
30
+ @State var telLabelView: Bool = false
31
+ @State var mailLabelView: Bool = false
32
+ @State var selectedPhoneLabels: String = ""
33
+ @Environment(\.dismiss) var dismiss
37
34
 
38
35
 
39
36
  var body: some View {
37
+
40
-
38
+ NavigationView {
39
+ List {
40
+
41
- ZStack {
41
+ HStack {
42
- VStack {
43
- HStack(alignment: .center){
44
42
  Spacer()
45
43
  ProfilePhotoSelect()
44
+ .padding()
46
45
  Spacer()
47
- }//PhotoPickre
46
+ }
47
+
48
48
 
49
- List {
49
+ Section {
50
+ TextField("姓", text: $profileData.firstName)
51
+ TextField("姓(フリガナ)", text: $profileData.firstNameFurigana)
52
+ TextField("名", text: $profileData.lastName)
53
+ TextField("名(フリガナ)", text: $profileData.lastNameFurigana)
54
+ TextField("会社", text: $profileData.company)
55
+ TextField("会社名(フリガナ)", text: $profileData.companyFurigana)
56
+ }// Name Section
57
+
58
+ Section {
59
+ ForEach(profileData.telNumber.indices, id: \.self) { i in
60
+ HStack {
61
+ Text(profileData.telLabels ?? "")
62
+ .foregroundColor(Color(.systemBlue))
63
+ .onTapGesture {
64
+ telLabelView.toggle()
65
+ }
66
+ .sheet(isPresented: $telLabelView) {
67
+ PhoneLabels()
68
+ }
69
+ Divider()
70
+ TextField("電話", text: $profileData.telNumber[i])
71
+ }
72
+ }
73
+ .onDelete(perform: rowRemove)
74
+
75
+
76
+
77
+ HStack {
78
+ Image(systemName: "plus.circle.fill")
79
+ .foregroundColor(Color(.systemGreen))
80
+ Divider()
81
+ Text("電話を追加")
82
+ .font(.callout)
83
+ .fontWeight(.light)
84
+ .padding(.horizontal)
85
+ }
86
+ .onTapGesture {
87
+ self.profileData.telNumber.append("")
88
+ withAnimation(){
89
+ editMode?.wrappedValue = .active
90
+ }
91
+
92
+ }
93
+ }// TelNumber Section
94
+
50
95
  Section {
51
- TextField("姓", text: $firstName)
96
+
52
- TextField("姓(フリガナ)",text: $firstNameFurigana)
53
- TextField("名",text: $lastName)
54
- TextField("名(フリガナ)",text: $lastNameFurigana)
55
- TextField("会社名",text: $company)
56
- TextField("会社名(フリガナ)", text: $companyFurigana)
57
- }//Name&company
58
-
59
- Section {
60
- ForEach(telNumber.indices, id: \.self) { telnum in
97
+ ForEach(profileData.emailAdress.indices, id: \.self) { x in
61
- TextField("電話番号", text: $telNumber[telnum])
98
+ TextField("メール", text: $profileData.emailAdress[x])
62
- }.onDelete(perform: rowDelete)
99
+ }.onDelete(perform: rowRemove)
63
-
100
+
101
+
64
102
  HStack {
65
103
  Image(systemName: "plus.circle.fill")
66
104
  .foregroundColor(Color(.systemGreen))
67
105
  Divider()
68
- Text("電話番号")
106
+ Text("メールを追加")
107
+ .font(.callout)
108
+ .fontWeight(.light)
109
+ .padding(.horizontal)
69
110
  }
70
111
  .onTapGesture {
71
- telNumber.append("")
112
+ profileData.emailAdress.append("")
72
113
  withAnimation(){
73
114
  editMode?.wrappedValue = .active
74
115
  }
75
116
  }
117
+ }// Email Section
118
+
119
+ Section {
120
+
121
+ NavigationLink {
122
+ Ringtone()
123
+ }label: {
124
+ Text("着信音")
125
+ .font(.callout)
126
+ .fontWeight(.light)
127
+ .foregroundColor(.black)
128
+ Text("デフォルト")
129
+ .padding(.horizontal)
130
+ .font(.callout)
131
+ .foregroundColor(.blue)
76
132
  }
77
-
133
+
134
+
78
135
  }
79
136
  }
137
+ .listStyle(.grouped)
138
+ .navigationBarTitle("新規連絡先",displayMode: .inline)
139
+ .navigationBarItems(leading: Button{
140
+ dismiss()
141
+ }label: {
142
+ Text("キャンセル")
143
+ }, trailing: Button {
144
+ print("DEBUG: Register user")
145
+ }label: {
146
+ Text("完了")
147
+ })
148
+ }
80
149
 
81
- }.listStyle(.grouped)
150
+
151
+
82
152
  }
153
+
83
- func rowDelete(offsets: IndexSet){
154
+ func rowRemove(offsets: IndexSet) {
84
- telNumber.remove(atOffsets: offsets)
155
+ profileData.telNumber.remove(atOffsets: offsets)
85
- }
156
+ }//項目を削除する際の処理
86
157
  }
87
158
  ```
88
159