Trying to display data on a UITableView from parse - ios

I'm trying to display data from parse onto a UITableView but it's only displaying a blank UITableView (no data being shown)
I have a University class in parse, as well as a universityEnrolledName column name
here is the code
import UIKit
import Parse
import ParseUI
class viewUniversityList: PFQueryTableViewController {
#IBOutlet var uiTableView: UITableView!
override init(style: UITableViewStyle, className: String!){
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder){
super.init(coder: aDecoder)
self.parseClassName = "University"
self.textKey = "universityEnrolledName"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "University")
query.orderByAscending("universityEnrolledName")
return query;
}
override func viewDidLoad() {
super.viewDidLoad()
uiTableView.delegate = self
uiTableView.dataSource = self
// 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 Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! PFTableViewCell!
if cell == nil {
cell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
if let universityEnrolledName = object?["universityEnrolledName"] as? String{
cell?.textLabel?.text = universityEnrolledName
}
if let classEnrolledName = object?["classEnrolledName"] as? String{
cell?.detailTextLabel?.text = classEnrolledName
}
return cell;
}
/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
}
does anyone have any advice on displaying the universityEnrolledName data from the University class (from Parse)? Thanks!

Here,
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 0
}
This method is used to display number rows in a tableview. Since you are returning 0, which means you are telling to your table view that your table should have zero row's.
Similarly
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
By default table view have one section, if you are explicitly providing some value it will be overridden.
So in both case you should return some positive number greater than zero.
The below method should return UITableViewCell, but you wrote PFTableViewCell. So change it.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! PFTableViewCell!
if cell == nil {
cell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
if let universityEnrolledName = object?["universityEnrolledName"] as? String{
cell?.textLabel?.text = universityEnrolledName
}
if let classEnrolledName = object?["classEnrolledName"] as? String{
cell?.detailTextLabel?.text = classEnrolledName
}
return cell;
}

override func viewDidLoad() {
super.viewDidLoad()
//Conform to the TableView Delegate and DataSource protocols
uiTableView.delegate = self //set delegate
uiTableView.dataSource = self // set datasource
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 0 //set count of section
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0 //set count of rows
}
Refere this:
how-to-make-a-simple-table-view-with-ios-8-and-swift
This might helps you :)

I don't write swift so forgive any syntax issues, but I expect you want something more like:
import UIKit
import Parse
import ParseUI
class viewUniversityList: PFQueryTableViewController {
#IBOutlet var uiTableView: UITableView!
override init(style: UITableViewStyle, className: String!){
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder){
super.init(coder: aDecoder)
self.parseClassName = "University"
self.textKey = "universityEnrolledName"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
override func viewDidLoad() {
super.viewDidLoad()
uiTableView.delegate = self
uiTableView.dataSource = self
// 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 queryForTable() -> PFQuery {
var query = PFQuery(className: "University")
query.orderByAscending("universityEnrolledName")
return query;
}
override func textKey() -> NSString {
return "universityEnrolledName"
}
// MARK: - Table view data source
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = super.tableView(tableView, dequeueReusableCellWithIdentifier:indexPath, object:object) as! PFTableViewCell!
if let classEnrolledName = object?["classEnrolledName"] as? String{
cell?.detailTextLabel?.text = classEnrolledName
}
return cell;
}

Related

Retrieving firebase children and populating them in a UITableView

Trying to query firebase children and retrieve a snapshot array of their data into a tableview. Not sure if I am implementing this correctly, but I am not the getting a runtime error. However, my tableview is just white with no objects displaying. Some feedback would be helpful. Thanks.
Here is my FB JSON tree structure
Here is my User class (var userList = User)
class CDetailTableViewController: UITableViewController {
static var imageCache = NSCache<AnyObject, UIImage>()
var userList = [User]()
var ref = FIREBASE.FBDataReference().ref
var refHandle: UInt!
override func viewDidLoad() {
super.viewDidLoad()
ref = FIREBASE.FBLink().FBref
configureCell()
}
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 {
// #warning Incomplete implementation, return the number of rows
return userList.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CDetailTableViewCell
cell.priceLabel?.text = userList[indexPath.row].priceLabel
cell.titleLabel?.text = userList[indexPath.row].titleLabel
cell.itemPhoto?.image = userList[indexPath.row].objectImage
return cell
}
func configureCell(){
let ref = FIRDatabase.database().reference()
let userID = FIRAuth.auth()?.currentUser?.uid
refHandle = ref.child("Enterpriser Listings").child("Sell Old Stuff - Listings").child(userID!).observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String : AnyObject] {
print("get dictionary")
print(dictionary)
let user = User()
user.setValuesForKeys(dictionary)
self.userList.append(user)
// Get user value
DispatchQueue.main.async {
print("reloaded")
self.tableView.reloadData()
}
}
})
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
May be the problem is with your Firebase reference, try like this way.
ref.child("Enterpriser Listings").child("Sell Old Stuff - Listings").observe(.value, with: { (snapshot:FIRDataSnapshot) in
var users = [User]()
for child in snapshot.children {
print("\((sweet as! FIRDataSnapshot).value)")
if let dictionary = child.value as? [String : AnyObject] {
let user = User()
user.setValuesForKeys(dictionary)
users.append(user)
}
}
self.userList = users
self.tableView.reloadData()
})
Simple question. Have you delegated your tableview?
class YourController: < other >, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
override func viewDidLoad() { //for example this function
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}

Table View only loads if I put phone in landscape mode

I have a custom table view, which when I run the app, shows up blank, like it hasnt been loaded, but when I tilt my phone to landscape mode, the entries appear, which really doesnt make sense to me. Any suggestions?
Edit: Here is my code
import UIKit
import Alamofire
import ObjectMapper
class LotteryTableViewController: UITableViewController {
let lotteryMachine = LotteryMachine()
var currentStandings: [Team] = []
var draftStandings: [Team] = []
override func viewDidLoad() {
super.viewDidLoad()
let headers = [
"User-agent": "LotteryMachine/1.0 (nilayneeranjun24#gmail.com)",
]
Alamofire.request(.GET, "https://erikberg.com/nba/standings.json",headers: headers)
.responseJSON { response in
let parentJson = Mapper<Standings>().map(response.2.value)
let standingsArray: [Team] = parentJson!.standing!
self.currentStandings=standingsArray
self.draftStandings=self.lotteryMachine.setPossibleCombinations(standingsArray)
self.draftStandings=self.lotteryMachine.setDraftPositions(self.draftStandings)
print (self.draftStandings.toJSON())
}
}
// 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 {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return draftStandings.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "LotteryTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! LotteryTableViewCell
let position = self.draftStandings[indexPath.row].draftingPosition!
let teamName = self.draftStandings[indexPath.row].lastName!
let record = String(self.draftStandings[indexPath.row].won!) + "-" + String(self.draftStandings[indexPath.row].lost!)
let player = "Ben Simmons"
cell.position.text = String(position)
cell.teamName.text = teamName
cell.record.text = String(record)
cell.player.text = player
cell.teamLogo.image = UIImage(named: "lakers")
// Configure the cell...
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Alamofire.request is async in nature. So when the table first loads, the request is still executing and your draftStandings doesn't have any data. When you rotate, the table is reloaded and by that time draftStandings does have some data already which the table shows.
Try adding a tableView.reloadData() after setting the draftStandings in the request response.

Does not conform to UITableViewDataSource - Parse app

I'm using a UITableView in a ViewController connected to TodayViewController. I want to use data from my Parse database to load into the TableView.
Here is my TodayViewController class:
import UIKit
class TodayViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet var InfoTableView: UITableView?
override func viewDidLoad() {
super.viewDidLoad()
InfoTableView!.delegate = self
InfoTableView!.dataSource = self
loadParseData()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadParseData() {
let query : PFQuery = PFQuery(className: "News")
query.orderByDescending("Headline")
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("NewCell") as! PFTableViewCell!
if cell == nil {
cell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "NewCell")
}
//Extract values from the PFObject to display in the table cell
if let Headline = object?["Headline"] as? String {
cell?.textLabel?.text = Headline
}
if let Subtitle = object?["SubtitleText"] as? String {
cell?.detailTextLabel?.text = Subtitle
}
return cell
}
This error crops up:
How do I solve the problem? Is there any mistake in the overall structure? Do request for more information if required.
Yes you are not confirm to protocol UITableViewDataSource because you don't have a required method
func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
So you need to inherit PFQueryTableViewController to use the methods you want
class TodayViewController: PFQueryTableViewController {
...
}
I think you have implemented all the delegate methods of tableview outside the main class, i mean there will be a open parenthesis { and the close parenthesis should be end of all the methods. try like this
import UIKit
class TodayViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet var InfoTableView: UITableView?
override func viewDidLoad() {
super.viewDidLoad()
InfoTableView!.delegate = self
InfoTableView!.dataSource = self
loadParseData()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadParseData() {
let query : PFQuery = PFQuery(className: "News")
query.orderByDescending("Headline")
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("NewCell") as! PFTableViewCell!
if cell == nil {
cell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "NewCell")
}
//Extract values from the PFObject to display in the table cell
if let Headline = object?["Headline"] as? String {
cell?.textLabel?.text = Headline
}
if let Subtitle = object?["SubtitleText"] as? String {
cell?.detailTextLabel?.text = Subtitle
}
return cell
}
}
Hope this will help.

ImagesTabViewController' does not conform to protocol 'UITableViewDataSource'

I know this question has been asked a million times, but I can't find a resolution to this specific issue. I'm using Xcode 6.3 beta 4 with Swift 1.2 and since the last update I haven't been able to get a regular UITableView with the supporting datasource and delegate protocols working.
I am getting the above error and "Definition conflicts with previous value" for the numberOfRowsInSection function. At this point I don't know if it's a Swift change or I am missing something. The tableview is connected properly..
Thanks for any help.
class ImagesTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var collectionInfo: NSArray = DataManager.getUserCollections()
var items: NSMutableArray = []
var namesArray: NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
APIManager().getData() { completed in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if completed {
self.collectionInfo = DataManager.getUserCollections()
var collectionNames: AnyObject = self.collectionInfo[3]
println(collectionNames)
self.items = NSMutableArray(array: self.collectionInfo)
} else {
//do something else
}
})
// Do any additional setup after loading the view.
}
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var collectionsAndArrays = PSCollection()
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")
// Configure the cell...
collectionsAndArrays = self.items[indexPath.row] as! PSCollection
cell.textLabel!.text = collectionsAndArrays.name
cell.detailTextLabel!.text = collectionsAndArrays.created_at
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
var numberOfCollections: Int = self.items.count
return numberOfCollections
}
}}
There is a bracket missing and didReceiveMemoryWarning must be overridden. Here is the revised code:
class ImagesTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var collectionInfo: NSArray = DataManager.getUserCollections()
var items: NSMutableArray = []
var namesArray: NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
APIManager().getData() { completed in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if completed {
self.collectionInfo = DataManager.getUserCollections()
var collectionNames: AnyObject = self.collectionInfo[3]
println(collectionNames)
self.items = NSMutableArray(array: self.collectionInfo)
} else {
//do something else
}
})
// Do any additional setup after loading the view.
}
} // <- Was missing!
// Override!
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var collectionsAndArrays = PSCollection()
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")
// Configure the cell...
collectionsAndArrays = self.items[indexPath.row] as! PSCollection
cell.textLabel!.text = collectionsAndArrays.name
cell.detailTextLabel!.text = collectionsAndArrays.created_at
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var numberOfCollections: Int = self.items.count
return numberOfCollections
}
}

Type does not have a member names 'objectForKey' and use of unresolved identifiers

Using swift/parse to attempt to populate custom cell in the following table view controller. The pfquery code seems to be going fine, but when I attempt to use the the data to populate cell.something.text with what should be returned results, I receive errors indicating that type does not a have a member named 'objectForKey' and Use of unresolved identifiers. The errors are specifically all occurring under the override func tableView(tableView..cellForRowAtIndexPath....
import UIKit
class TimeLineTableViewController: UITableViewController {
var timelineData:NSMutableArray = NSMutableArray()
override init(style: UITableViewStyle) {
super.init(style: style)
// Custom initialization
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func loadData(){
timelineData.removeAllObjects()
//let predicate = NSPredicate(format: PFuser = PFUser.current)
var findTimelineData:PFQuery = PFQuery(className: "event")
//findTimelineData.whereKey(PFUser.self, equalTo: PFUser.currentUser())
findTimelineData.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
self.timelineData.addObject(object)
println(object.objectId)
}
let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
self.timelineData = array as NSMutableArray
self.tableView.reloadData()
}
} else {
// Log details of the failure
println("Error: \(error) \(error.userInfo!)")
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// 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 Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return timelineData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:TimeLineTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TimeLineTableViewCell
let event:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
cell.eventLabel.alpha = 0
cell.dateLabel.alpha = 0
cell.minutesLabel.alpha = 0
cell.eventLabel.text = Category.objectForKey("content") as String
cell.minutesLabel.text = duration.objectForKey
var dataFormatter:NSDateFormatter = NSDateFormatter()
dataFormatter.dateFormat = "yyyy-MM-dd HH:mm"
cell.dateLabel.text = dataFormatter.stringFromDate(category.createdAt)
var findRecorder:PFQuery = PFUser.query()
findRecorder.whereKey("objectId", equalTo: event.objectForKey(user).objectId)
findRecorder.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
let user:PFUser = (objects as NSArray).lastObject as PFUser
UIView.animateWithDuration(0.5, animations: {
cell.eventLabel.alpha = 1
cell.dateLabel.alpha = 1
cell.minutesLabel.alpha = 1
})
}
}
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
}
Your problem is that you're using variables you didn't initialize anywhere in your code:
cell.minutesLabel.text = duration.objectForKey
^
cell.dateLabel.text = dataFormatter.stringFromDate(category.createdAt)
^
You never initialize duration or category in your code. So you can't access it. You first need to initialize it.
Also I'm not sure but it looks like that you don't import the Parse framework (maybe you do but it's not in the code you've provided)
So you will need to import it first:
import Parse

Resources