2016-02-05 40 views
0

我有下面的代碼,現在我試圖實現UITableView的附件。 所有的數據都來自Parse,即使有幫助瞭解如何執行常規配件的教程,但我無法找到一個實際教導如何從Parse等在線數據庫獲取數據的人。解析Swift UITableView附件

// 
// 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

+0

請添加您遇到的問題。描述你在哪裏得到錯誤,或者你在哪裏找到不滿意的結果。它會給我們一個更好的場景來解決你的問題。 –

+0

嗨,我目前沒有遇到任何錯誤。我甚至不知道要在代碼中放置什麼。如果我確實遇到任何錯誤,我一定會放錯誤日誌。 – JackyBoi

回答

0

從外觀上來看下面一個例子,你想將你的數據傳遞給一個細節視圖,在這種情況下,你應該這樣做,假設你已經在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 
       } 
      }ˍ 
     } 
+0

2016-02-06 01:31:05.904 iLegaltwo [2737:155743]試圖在釋放視圖控制器時加載視圖的視圖是不允許的,並且可能導致未定義的行爲() 獲取上述內容錯誤。 – JackyBoi