每个人都试图从一个表中获取数据,使用指针,例如用户表和歌曲表,当你点击一个用户时,它会显示歌曲表中的歌曲列表特定于我尝试使用此方法的用户对象ID但是我收到错误query.wherekey("" equalTo: (PFUser.current()?.objectId!)!)
这是我的代码
var users = [""]
var userIDs = [""]
var isFollowing = ["" : true]
override func viewDidLoad() {
super.viewDidLoad()
//load user query
let query = PFUser.query ()
query?.findObjectsInBackground(block: { (objects, error) in
if error != nil {
print(error!)
} else if let users = objects {
for objects in users {
if let user = objects as? PFUser {
self.users.append(user.username!)
self.userIDs.append(user.objectId!)
let query = PFQuery(className: "Followers")
query.whereKey("Follower", equalTo: (PFUser.current()?.objectId!)!)
query.whereKey("Following", equalTo: user.objectId!)
query.findObjectsInBackground(block: { (objects, error) in
if let objects = objects {
if objects.count > 0 {
self.isFollowing[user.objectId!] = true
} else {
self.isFollowing[user.objectId!] = false
}
if self.isFollowing.count == self.users.count {
self.tableView.reloadData()
}
}
})
}
}
}
})
谢谢大家
**HERE IS MY CODE FOR THE FIRST VIEW WHERE I AM ABLE TO GET ALL USERS AND SEGUE TO ANOTHER TABLE VIEW CONTROLLER**
//
// users.swift
//
//
// Created by Nawir on 1/17/17.
// Copyright © 2017 Nawir. All rights reserved.
//
import Foundation
import Parse
class artistsviewcontroller: UITableViewController {
var users = [""]
var userIDs = [""]
override func viewDidLoad() {
super.viewDidLoad()
//updating users array
let query = PFUser.query ()
query?.findObjectsInBackground(block: { (objects, error) in
if error != nil {
print(error!)
} else if let users = objects {
for objects in users {
if let user = objects as? PFUser {
self.users.append(user.username!)
self.userIDs.append(user.objectId!)
}
}
}
self.tableView.reloadData()
})
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return users.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Usercell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! mTableViewCell
Usercell.textLabel!.text = users[indexPath.row]
return Usercell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// print("rowtapped: \(indexPath.row)")
let ItemlistTableViewController = self.storyboard?.instantiateViewController(withIdentifier: "itemviewscont") as! itemviewscont
self.navigationController?.pushViewController(ItemlistTableViewController, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
这是我的第二个TABLEVIEWCONTROLLER
// itemviews.swift
//
//
// Created by Nawir on 1/17/17.
// Copyright © 2017 Nawir. All rights reserved.
//
import Foundation
import Parse
class itemviewscont: UITableViewController {
var users = [String: String] ()
var itemname = [String] ()
override func viewDidLoad() {
super.viewDidLoad()
//query to get all user data from parse
let query = PFUser.query()
query?.findObjectsInBackground { (objects, error) in
if let users = objects {
self.users.removeAll()
for object in users {
if let user = object as? PFUser {
// self.users = [user.objectId!]
self.users[user.objectId!] = user.username!
}
}
}
//query to make connection
let getfollow = PFQuery(className: "Mkitems")
getfollow.whereKey("user", equalTo: PFUser.current()!)
getfollow.findObjectsInBackground(block: { (objects, error) in
if let followers = objects {
for object in followers {
if let follower = object as? PFObject {
let mainuser = follower["User"]
let query = PFQuery(className: "Music")
query.whereKey("fuser", equalTo: mainuser!)
query.findObjectsInBackground(block: { (objects,error) in
if let nitems = objects {
for object in nitems {
if let nitem = object as? PFObject {
self.musicname.append(nitem["name_title"] as! String)
self.tableView.reloadData()
}
}
}
})
}
}
}
})
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemname.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "mscell", for: indexPath)
cell.textLabel?.text = itemname[indexPath.row]
return cell
}
//dont pass this line its the end!
}
谢谢你们所有人
答案 0 :(得分:0)
如果您搜索当前用户对象(假设Follower是指针),请使用
var oracledb = require('oracledb');
oracledb.getConnection(
{
user : "hr",
password : "welcome",
connectString : "hostname:port/sid"
})
.then(function(conn) {
return conn.execute(
"SELECT department_id, department_name " +
"FROM departments " +
"WHERE manager_id < :id",
[110] // bind value for :id
)
.then(function(result) {
console.log(result.rows);
return conn.close();
})
.catch(function(err) {
console.error(err);
return conn.close();
});
})
.catch(function(err) {
console.error(err);
});
而不是:
query.whereKey("Follower", equalTo: PFUser.current()!)