我可以获取用户及其个人资料图片但是,我想仅返回表格中的当前用户,因为我使用NSMutableArray来保存用户价值。
更新:我已编辑以显示我的完整课程
var userArray : NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
loadParseData()
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
// Do any additional setup after loading the view.
}
func loadParseData() {
var query : PFQuery = PFUser.query()!
query.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil {
if let objects = objects {
for object in objects {
self.userArray.addObject(object)
}
self.tableView.reloadData()
}
} else {
println("There is an error")
}
}
}
// Initialise the PFQueryTable tableview
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//Configure PFQueryTableView
self.parseClassName = "User"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "User")
return query
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//How can I return PFUser.currentUser() here?
return self.userArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let row = indexPath.row
var userProfileImage = userArray[row] as! PFUser
var username = userProfileImage.username as String!
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ProfileTableViewCell
//Display Profile Image
PFUser.currentUser()?["profile_picture"]
if let pfimage = PFUser.currentUser()?["profile_picture"] as? PFFile{
pfimage.getDataInBackgroundWithBlock({
(result, error) in
cell.profileImage.image = UIImage(data: result!)
cell.userName.text = username
})
}
return cell
}
答案 0 :(得分:0)
您可以将数组声明为AnyObject数组。试试这个:
var userArray : AnyObject = []
尝试使用一些断点来查看变量并了解最新情况。
此外,如果您的表视图中只有一个部分,则无需拨打numberOfSectionsInTableView
,因为默认值为1
。