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

質問編集履歴

2

新たな問題を追記

2016/05/11 06:11

投稿

DaikiOgawa
DaikiOgawa

スコア15

title CHANGED
File without changes
body CHANGED
@@ -55,4 +55,91 @@
55
55
  let storyboard = UIStoryboard(name: "Main", bundle: nil)
56
56
  let groupsView = storyboard.instantiateViewControllerWithIdentifier("GroupsViewController")
57
57
  self.navigationController?.pushViewController(groupsView, animated: true)
58
+ ```
59
+
60
+
61
+ 【新たな問題】
62
+ TouchUpイベントが複数回呼ばれてしまう。
63
+ addTagetの仕方が良くないのかなと思うのですが、どうすればよいかわかりません。。
64
+
65
+ ```Swift
66
+ // MainViewCellInfo.swift
67
+
68
+ import Foundation
69
+
70
+ class MainViewCellInfo {
71
+ private(set) var projectName: String!
72
+ init(cellData cellData_: [String: AnyObject]){
73
+ projectName = cellData_["projectName"] as! String
74
+ }
75
+ }
76
+ ```
77
+
78
+ ```Swift
79
+
80
+ // MainViewTableCell.swift
81
+
82
+ import UIKit
83
+
84
+ class MainViewTableCell: UITableViewCell{
85
+
86
+ @IBOutlet weak var projectNameLabel: UILabel!
87
+ @IBOutlet weak var Btn: UIButton!
88
+
89
+ class func nibName() -> String {
90
+ // クラス名と nib 名が同じ前提
91
+ return String(self)
92
+ }
93
+
94
+ class func cellId() -> String {
95
+ return String(self)
96
+ }
97
+
98
+ func setupWith(cellInfo cellInfo_: MainViewCellInfo) {
99
+ self.projectNameLabel.text = cellInfo_.projectName
100
+ //BtnにIDをセット
101
+ self.Btn.tag = cellInfo_.id
102
+ self.Btn.addTarget(MainViewController(), action: #selector(MainViewController.onMessageBtnClick(_:)), forControlEvents: .TouchUpInside)
103
+ }
104
+ }
105
+
106
+ ```
107
+
108
+ ```Swift
109
+ // MainViewController.swift
110
+
111
+ import UIKit
112
+ import Alamofire
113
+ import SwiftyJSON
114
+
115
+ class GroupsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
116
+
117
+ @IBOutlet weak var TableView: UITableView!
118
+
119
+ override func viewDidLoad() {
120
+ super.viewDidLoad()
121
+
122
+ self.TableView.delegate = self
123
+ self.TableView.dataSource = self
124
+ self.TableView?.rowHeight = 80.0
125
+
126
+ }
127
+
128
+ func tableView(TableView: UITableView, numberOfRowsInSection section: Int) -> Int {
129
+ print(jsonArray.count)
130
+ return jsonArray.count
131
+ }
132
+
133
+ func tableView(TableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
134
+ 色々書いてます
135
+ }
136
+
137
+ func onMessageBtnClick(sender: UIButton) {
138
+ self.delegate._selectedProjectId = sender.tag
139
+ let storyboard = UIStoryboard(name: "Main", bundle: nil)
140
+ let nextVC = storyboard.instantiateViewControllerWithIdentifier("NextViewController")
141
+ self.navigationController?.pushViewController(nextVC, animated: true)
142
+ }
143
+ }
144
+
58
145
  ```

1

解決法を記載

2016/05/11 06:11

投稿

DaikiOgawa
DaikiOgawa

スコア15

title CHANGED
File without changes
body CHANGED
@@ -39,4 +39,20 @@
39
39
  tableViewに入れる要素をカウントするmethodまで入っていってません。
40
40
 
41
41
  IBOutletし直したり、名前を変えてみたりしましたが、うまくいきません。
42
- よろしくお願いします。
42
+ よろしくお願いします。
43
+
44
+
45
+ 【解決法】
46
+
47
+ 元のコード
48
+ ```Swift
49
+ let groupsView = GroupsViewController()
50
+ self.navigationController?.pushViewController(groupsView, animated: true)
51
+ ```
52
+
53
+ 修正後のコード
54
+ ```Swift
55
+ let storyboard = UIStoryboard(name: "Main", bundle: nil)
56
+ let groupsView = storyboard.instantiateViewControllerWithIdentifier("GroupsViewController")
57
+ self.navigationController?.pushViewController(groupsView, animated: true)
58
+ ```