質問編集履歴

5

ログの追記

2017/02/15 08:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -229,3 +229,49 @@
229
229
 
230
230
 
231
231
  ```
232
+
233
+
234
+
235
+ ###コンソールでbtコマンドをたたいたときのログ
236
+
237
+
238
+
239
+ ```
240
+
241
+ * thread #1: tid = 0x9380f, 0x0000000196863bdc libobjc.A.dylib`objc_msgSend + 28, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x110000)
242
+
243
+ frame #0: 0x0000000196863bdc libobjc.A.dylib`objc_msgSend + 28
244
+
245
+ frame #1: 0x000000018988d398 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
246
+
247
+ frame #2: 0x0000000189876474 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 612
248
+
249
+ frame #3: 0x000000018988cd34 UIKit`-[UIControl touchesEnded:withEvent:] + 592
250
+
251
+ frame #4: 0x000000018988c9c0 UIKit`-[UIWindow _sendTouchesForEvent:] + 700
252
+
253
+ frame #5: 0x0000000189885efc UIKit`-[UIWindow sendEvent:] + 684
254
+
255
+ frame #6: 0x0000000189859120 UIKit`-[UIApplication sendEvent:] + 264
256
+
257
+ frame #7: 0x0000000189afa2b8 UIKit`_UIApplicationHandleEventFromQueueEvent + 15424
258
+
259
+ frame #8: 0x0000000189857634 UIKit`_UIApplicationHandleEventQueue + 1716
260
+
261
+ frame #9: 0x0000000184d98240 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
262
+
263
+ frame #10: 0x0000000184d974e4 CoreFoundation`__CFRunLoopDoSources0 + 264
264
+
265
+ frame #11: 0x0000000184d95594 CoreFoundation`__CFRunLoopRun + 712
266
+
267
+ frame #12: 0x0000000184cc12d4 CoreFoundation`CFRunLoopRunSpecific + 396
268
+
269
+ frame #13: 0x000000018e5df6fc GraphicsServices`GSEventRunModal + 168
270
+
271
+ frame #14: 0x00000001898bef40 UIKit`UIApplicationMain + 1488
272
+
273
+ * frame #15: 0x00000001000419f0 advicebook`main + 140 at AppDelegate.swift:12
274
+
275
+ frame #16: 0x0000000196efaa08 libdyld.dylib`start + 4
276
+
277
+ ```

4

ソースコードの修正

2017/02/15 08:43

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -104,6 +104,12 @@
104
104
 
105
105
  self.automaticallyAdjustsScrollViewInsets = false
106
106
 
107
+
108
+
109
+ self.collectionView!.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell1")
110
+
111
+ self.collectionView!.register(UINib(nibName: "CollectionViewCell2", bundle: nil), forCellWithReuseIdentifier: "cell2")
112
+
107
113
  }
108
114
 
109
115
 
@@ -172,8 +178,6 @@
172
178
 
173
179
  if(indexPath.row == 0 || indexPath.row == 1) {
174
180
 
175
- self.collectionView!.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell1")
176
-
177
181
  let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath as IndexPath) as! CollectionViewCell
178
182
 
179
183
  cell1.setCell(imageName: screenNames[indexPath.row])
@@ -184,8 +188,6 @@
184
188
 
185
189
  else {
186
190
 
187
- self.collectionView!.register(UINib(nibName: "CollectionViewCell2", bundle: nil), forCellWithReuseIdentifier: "cell2")
188
-
189
191
  let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath as IndexPath) as! CollectionViewCell2
190
192
 
191
193
  cell2.setCell(imageName: screenNames[indexPath.row])

3

ソースコードの修正

2017/02/14 12:49

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -40,14 +40,12 @@
40
40
 
41
41
  // カスタムセルクラス
42
42
 
43
- class CollectionViewCell1: CommonCollectionViewCell {
43
+ class CollectionViewCell2: CommonCollectionViewCell {
44
44
 
45
45
 
46
46
 
47
47
  @IBOutlet weak var mainImage: UIImageView!
48
48
 
49
- @IBOutlet weak var buttonA: UIButton!
50
-
51
49
 
52
50
 
53
51
  override func awakeFromNib() {
@@ -64,90 +62,168 @@
64
62
 
65
63
  self.mainImage.image = UIImage(named: imageName)
66
64
 
67
- let buttonAImage = UIImage(named: "image01")
68
-
69
- self.buttonA.setBackgroundImage(buttonAImage, for: .normal)
70
-
71
- self.buttonA.setTitle("", for: UIControlState(rawValue: 0))
72
-
73
- }
65
+ }
66
+
67
+
68
+
74
-
69
+ }
70
+
75
-
71
+ ```
72
+
73
+
74
+
76
-
75
+ ```swift
76
+
77
+ // ViewControllerクラス
78
+
79
+ class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
80
+
81
+
82
+
83
+ var screenHeight: CGFloat!
84
+
85
+ var screenWidth: CGFloat!
86
+
87
+
88
+
89
+ let screenNames = ["main01", "main02", "main03", "main09", "main02", "main03", "main09", "main02"]
90
+
91
+
92
+
93
+ override func viewDidLoad() {
94
+
95
+ super.viewDidLoad()
96
+
97
+
98
+
99
+ let statusBar = UIView(frame:CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: 20.0))
100
+
101
+ statusBar.backgroundColor = UIColor.white
102
+
103
+ view.addSubview(statusBar)
104
+
105
+ self.automaticallyAdjustsScrollViewInsets = false
106
+
107
+ }
108
+
109
+
110
+
111
+ // 希望のセルサイズを返す
112
+
113
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
114
+
115
+
116
+
117
+ let screenSize: CGRect = UIScreen.main.bounds
118
+
119
+ screenWidth = screenSize.width
120
+
121
+ screenHeight = screenSize.height
122
+
123
+ let returnSize = CGSize(width: screenSize.width, height: screenSize.height)
124
+
125
+
126
+
127
+ return returnSize
128
+
129
+ }
130
+
131
+
132
+
133
+ //セルのアイテムのマージンを設定
134
+
135
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
136
+
137
+ return UIEdgeInsetsMake(20.0 , 0.0 , 0.0 , 0.0 ) //マージン(top , left , bottom , right)
138
+
139
+ }
140
+
141
+
142
+
143
+ //セル間のマージンを削除
144
+
145
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
146
+
147
+ return 0.0
148
+
149
+ }
150
+
151
+
152
+
153
+ //データの個数を返す
154
+
155
+ override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
156
+
157
+ {
158
+
159
+ return screenNames.count
160
+
161
+ }
162
+
163
+
164
+
165
+ //データを返す
166
+
167
+ override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
168
+
169
+ {
170
+
171
+ var cell: CommonCollectionViewCell!
172
+
173
+ if(indexPath.row == 0 || indexPath.row == 1) {
174
+
175
+ self.collectionView!.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell1")
176
+
177
+ let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath as IndexPath) as! CollectionViewCell
178
+
179
+ cell1.setCell(imageName: screenNames[indexPath.row])
180
+
181
+ cell = cell1
182
+
183
+ }
184
+
185
+ else {
186
+
187
+ self.collectionView!.register(UINib(nibName: "CollectionViewCell2", bundle: nil), forCellWithReuseIdentifier: "cell2")
188
+
189
+ let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath as IndexPath) as! CollectionViewCell2
190
+
191
+ cell2.setCell(imageName: screenNames[indexPath.row])
192
+
193
+ cell = cell2
194
+
195
+ }
196
+
197
+
198
+
199
+ return cell
200
+
201
+ }
202
+
203
+
204
+
205
+ // ボタンタップで実行されるメソッド
206
+
77
- @IBAction func modalA(_ sender: Any) {
207
+ @IBAction func modalView(_ sender: UIButton) {
78
208
 
79
209
  print("tapButtonA")
80
210
 
81
-
211
+ }
212
+
213
+
214
+
82
-
215
+ override func didReceiveMemoryWarning() {
216
+
217
+ super.didReceiveMemoryWarning()
218
+
83
- // secondViewControllerのインスタンス生成.
219
+ // Dispose of any resources that can be recreated.
84
-
85
- let modalView = ModalViewController()
86
-
87
-
88
-
89
- // navigationControllerのrootViewControllerにsecondViewControllerをセット.
90
-
91
- let nav = UINavigationController(rootViewController: modalView)
92
-
93
-
94
-
95
- // 画面遷移.
96
-
97
- self.present(nav, animated: true, completion: nil)
98
220
 
99
221
  }
100
222
 
101
223
  }
102
224
 
225
+
226
+
227
+
228
+
103
229
  ```
104
-
105
-
106
-
107
- よろしくお願い致します。
108
-
109
-
110
-
111
-
112
-
113
- ### 追記
114
-
115
- カスタムセルクラス
116
-
117
- ```swift
118
-
119
-
120
-
121
- let view = ViewController()
122
-
123
-
124
-
125
- @IBAction func modalA(_ sender: Any) {
126
-
127
- print("tapButtonA")
128
-
129
- view.modalView()
130
-
131
- }
132
-
133
- ```
134
-
135
-
136
-
137
-
138
-
139
- ViewControllerクラス
140
-
141
- ```swift
142
-
143
- func modalView() {
144
-
145
- let modalView = ModalViewController()
146
-
147
- // 画面遷移.
148
-
149
- self.present(modalView, animated: true, completion: nil)
150
-
151
- }
152
-
153
- ```

2

ソースの追記

2017/02/14 09:36

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -105,3 +105,49 @@
105
105
 
106
106
 
107
107
  よろしくお願い致します。
108
+
109
+
110
+
111
+
112
+
113
+ ### 追記
114
+
115
+ カスタムセルクラス
116
+
117
+ ```swift
118
+
119
+
120
+
121
+ let view = ViewController()
122
+
123
+
124
+
125
+ @IBAction func modalA(_ sender: Any) {
126
+
127
+ print("tapButtonA")
128
+
129
+ view.modalView()
130
+
131
+ }
132
+
133
+ ```
134
+
135
+
136
+
137
+
138
+
139
+ ViewControllerクラス
140
+
141
+ ```swift
142
+
143
+ func modalView() {
144
+
145
+ let modalView = ModalViewController()
146
+
147
+ // 画面遷移.
148
+
149
+ self.present(modalView, animated: true, completion: nil)
150
+
151
+ }
152
+
153
+ ```

1

タイトルの修正

2017/02/13 09:01

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- xibに配置したボタンをタップして画像をモーダル表示させたい
1
+ UICollectionView xibに配置したボタンをタップして画像をモーダル表示させたい
test CHANGED
File without changes