1
これについての情報はありません。私は選択した行(チェックマークを持つ行)を新しく作成したグループとしてFirebaseデータベースに送信したいと思います。私は私のテーブルビューの外に "グループの作成"ボタンを作成しました。選択した行からデータを渡す方法に関する情報やリソースが必要ですが、トピックで何かを見つけることができませんでした。チェックマーク付きの行を選択したり選択解除する方法については多くの情報がありますが、選択したチェックマーク付き行からアレイまたはオンラインデータベースに情報を送信する方法については何も表示されません。選択したuitableview行を新しく作成したグループに送信する方法
class FriendsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var userList = [Users]()
@IBOutlet weak var myTableView: UITableView!
@IBAction func createGroup(_ sender: Any) {
}
final let urlString = "https://api.lookfwd.io/v1/test/users"
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userList.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyTableViewCell
myCell.selectionStyle = UITableViewCellSelectionStyle.none
myCell.nameLabel.text = userList[indexPath.row].name
return myCell
}
override func viewDidLoad() {
super.viewDidLoad()
self.downloadJsonWithTask()
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if myTableView.cellForRow(at: indexPath)?.accessoryType == UITableViewCellAccessoryType.checkmark{
myTableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.none}
else{
myTableView.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark
}
}
func downloadJsonWithTask() {
let url = NSURL(string: urlString)
var downloadTask = URLRequest(url: (url as URL?)!, cachePolicy: URLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 20)
downloadTask.httpMethod = "GET"
URLSession.shared.dataTask(with: downloadTask, completionHandler: {(data, response, error) -> Void in
if let response = data {
if let jsonData = try? JSONSerialization.jsonObject(with: response, options: .allowFragments) as? [String:Any] {
if let dataArray = (jsonData as AnyObject).value(forKey: "users") as? [[String:Any]] {
for data in dataArray{
let newUser = Users(data: data)
self.userList.append(newUser)
print(jsonData!)
}
}
OperationQueue.main.addOperation({
for use in self.userList {
print(use.name ?? "")
}
self.myTableView.reloadData()
})
print(jsonData!)
}
}
}).resume()
}
}
を取得したい場合は、その後THID
のようにクリックされたインデックスを記録する必要がありますアレイ? – user8000557
@ user8000557 'selected'配列をループし、' userList'配列から 'User'オブジェクトをインデックスで取得し、各ユーザの名前を取得します。' –
@IBAction func createGroup(_ sender:Any){ for(selected、name ) プリント(選択、名前) } } – user8000557