我有以下代码,现在我正在尝试实现UITableView的附件。所有数据都来自 Parse,即使有教程帮助如何做普通配件,如果我从像 Parse 这样的在线数据库获取数据,我找不到一个真正教如何做到这一点的教程。
//
// Listdoctors.swift
// ihealthtwo
//
// Created by David on 10/1/16.
// Copyright © 2016 ƒ. All rights reserved.
//
import UIKit
import Parse
class Listdoctors: UITableViewController {
@IBOutlet var listdoctors: UITableView!
var doctorName = [String]()
var doctorRate = [NSInteger]()
var doctorDetail = [String]()
var refresher: UIRefreshControl!
func refresh()
{
let query = PFQuery(className: "doctors")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock(
{
(listll: [PFObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
print("Successfully retrieved (listll!.count) names of the lawyers.")
// Do something with the found objects
if let objects = listll {
for object in objects {
print(object)
self.doctorName.append(object["doctorName"] as! String)
self.doctorRate.append(object["Rate"] as! NSInteger)
self.doctorDetail.append(object["doctorContent"] as! String)
// print(object["Lawyer_Name"] as! String )
// self.lawyersname.append(object["Lawyer_Name"] as! String)
//self.lblName.text = object["Lawyer_Name"] as? String
}
self.listdoctors.reloadData()
}
print(self.doctorName.count)
} else {
// Log details of the failure
print("Error: (error!) (error!.userInfo)")
}
self.tableView.reloadData()
self.refresher.endRefreshing()
})
}
override func viewDidLoad() {
super.viewDidLoad()
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pull to refrehsh")
refresher.addTarget(self, action: "refresh", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresher)
refresh()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return doctorName.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let doctorcell: doctorsCell = tableView.dequeueReusableCellWithIdentifier("doctorsproto") as! doctorsCell
// Configure the cell...
doctorcell.doctorname.text = doctorName[indexPath.row]
doctorcell.doctorcontent.text = doctorDetail[indexPath.row]
doctorcell.doctorrate.text = "(doctorRate [indexPath.row])"
//lawyercell.lblExpll.text = lawyerExp[indexPath.row]
//lawyercell.lblPracareall.text = lawyerPracArea[indexPath.row]
//profImages[indexPath.row].getDataInBackgroundWithBlock{(imageData: NSData?, error: NSError?) -> Void in
// if imageData != nil {
// let image = UIImage(data: imageData!)
// lawyercell.imageLawyer.image = image
// }
// else
// {
// print(error)
// } }
return doctorcell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
print(indexPath.row)
}
// MARK: - Navigation to doctor detail
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier
{
switch identifier
{
doctor "TodoctorDetail":
let productDetailVC = segue.destinationViewController as! doctorDetail
if let indexPath = self.tableView.indexPathForCell(sender as! UITableViewCell)
{
}
default: break
}
}ˍ
}
//MARK: - Helper Method
//func productAtIndexPath(indexPath: NSIndexPath) ->?? (waht should i Put here)
}
我的最后一行代码不是我确定我到底需要返回什么,这是我遵循的示例https://www.youtube.com/watch?v=c-E_EbMR9wA
从外观上看,您正在尝试将数据传递到详细信息视图,在这种情况下,假设您已经在 detailView 中定义了正确的 indexPath 和变量,您应该执行类似的事情。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier
{
switch identifier
{
doctor "TodoctorDetail":
let productDetailVC = segue.destinationViewController as! doctorDetail
if let indexPath = self.tableView.indexPathForCell(sender as! UITableViewCell)
{
// Assuming you have the proper indexPath defined here for the selected cell and that you have these three values already defined in your productDetailVC
productDetailVC.doctorName = doctorName[indexPath.row]
productDetailVC.doctorContent = doctorContent[indexPath.row]
productDetailVC.doctorRate = doctorRating[indexPath.row]
}
default: break
}
}ˍ
}