I'm Stuck on this issue and I have tried different 'fixes' for this issue however nothing seems to work. Code for Ref:
class FindAParty:UITableViewController{
var partyData:NSMutableArray! = NSMutableArray()
//var user:NSMutableArray = NSMutableArray()
override init(style: UITableViewStyle){
super.init(style: style)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//fatalError("init(coder:) has not been implemented")
}
#IBAction func loadData(){
print ("Load Data went through")
partyData.removeAllObjects()
print ("Remove ALL Objeccts")
let findPartyData:PFQuery = PFQuery(className: "Party")
print("PFQuery...")
findPartyData.findObjectsInBackground{
(objects:[PFObject]?, error:Error?)->Void in
if error != nil {
print("Error")
}else{
for object in objects!{
let party:PFObject = object as PFObject
self.partyData.add("party")
}
let array:NSArray = self.partyData.reverseObjectEnumerator().allObjects as NSArray
self.partyData = NSMutableArray(array: array)
self.tableView.reloadData()
}
}
}
override func viewDidAppear(_ animated: Bool) {
self.loadData()
print("View Did Appear")
}
override func viewDidLoad() {
super.viewDidLoad()
print("ViewDidLoad")
//self.loadData()
// 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.
}
// #pragma mark - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return partyData.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FindAPartyCell
//Error Happens Below
let party:PFObject = self.partyData.object(at: indexPath.row) as! PFObject
cell.typeOfPartyLabel.alpha = 0
cell.timeOfPartyLabel.alpha = 0
cell.usernameLabel.alpha = 0
cell.typeOfPartyLabel.text = party.object(forKey: "partyTitle") as? String
cell.timeOfPartyLabel.text = party.object(forKey: "partyTime") as? String
cell.usernameLabel.text = party.object(forKey: "Username") as? String
// var dataFormatter:NSDateFormatter = NSDateFormatter()
//dataFormatter.dateFormat = "yyyy-MM-dd HH:mm"
//cell.timestampLabel.text = dataFormatter.stringFromDate(sweet.createdAt)
let findUser:PFQuery = PFUser.query()!
findUser.whereKey("objectId", equalTo: party.object(forKey: "Username")!)
findUser.findObjectsInBackground {
(objects:[PFObject]?, error: Error?) -> Void in // Changes NSError to Error
if error == nil{
let user:PFUser = (objects)!.last as! PFUser
cell.usernameLabel.text = user.username
UIView.animate(withDuration: 0.5, animations: {
cell.typeOfPartyLabel.alpha = 1
cell.timeOfPartyLabel.alpha = 1
cell.usernameLabel.alpha = 1
})
}
}
return cell
}}
Someone recommended changing : let party:PFObject = self.partyData.object(at: indexPath.row) as! PFObject
to :
let party = self.partyData.object(at: indexPath!.row)
However this did not fix it and I am at a loss to how I should fix it the app build successfully and every other aspect of it runs however this is the only part that fails. I am using Parse and Amazon as my backend.
Declare the data source array
var partyData = [PFObject]()
and change loadData() to
#IBAction func loadData(){
print ("Load Data went through")
partyData.removeAll()
print ("Remove ALL Objeccts")
let findPartyData = PFQuery(className: "Party")
print("PFQuery...")
findPartyData.findObjectsInBackground {
(objects:[PFObject]?, error:Error?)->Void in
if error != nil {
print(error!)
} else{
if let objects = objects {
self.partyData = objects.reversed()
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
}
and get a row:
let party = self.partyData[indexPath.row]
Finally replace in cellForRowAt
if error == nil {
let user:PFUser = (objects)!.last as! PFUser
with
if users = objects as? [PFUser], !users.isEmpty {
let user = users.last!
Related
I have been Stuck on this error for awhile and I have searched and researched possible fixes for this and I cannot seem to find any. This the Same Code I used for an earlier IOS App and now it fails to work, I have taken the needed actions to update to the current Swift 3.1 Language however now I am stuck with the Following error:
Cannot convert value of type '[PFObject]?' to type 'NSArray' in coercion
So First off I'm not even sure where to begin fixing the Error.
Here is the Section where the Error Shows up:
findUser.findObjectsInBackground {
(objects:[PFObject]?, error: Error?) -> Void in // Changes NSError to Error
if error == nil{
let user:PFUser = (objects as NSArray).lastObject as! PFUser
cell.usernameLabel.text = user.username
UIView.animate(withDuration: 0.5, animations: {
cell.typeOfPartyLabel.alpha = 1
cell.timeOfPartyLabel.alpha = 1
cell.usernameLabel.alpha = 1
})
}
}
return cell
}
and for ref my whole UITableView Class:
import Foundation
import Parse
import UIKit
class FindAParty:UITableViewController{
var partyData:NSMutableArray! = NSMutableArray()
var user:NSMutableArray = NSMutableArray()
override init(style: UITableViewStyle){
super.init(style: style)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
#IBAction func loadData(){
partyData.removeAllObjects()
var findPartyData:PFQuery = PFQuery(className: "Party")
findPartyData.findObjectsInBackground{
(objects:[PFObject]?, error:Error?)->Void in
if error != nil {
print("Error")
}
else{
for object in objects!{
let party:PFObject = object as PFObject
self.partyData.add("Party")
}
let array:NSArray = self.partyData.reverseObjectEnumerator().allObjects as NSArray
self.partyData = NSMutableArray(array: array)
self.tableView.reloadData()
}
}
}
override func viewDidAppear(_ animated: Bool) {
self.loadData()
}
// #pragma mark - Table view data source
func numberOfSectionsInTableView(tableView: UITableView?) -> Int { return 1 }
override func tableView(_ tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
return partyData.count
}
func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
let cell:FindAPartyCell = tableView!.dequeueReusableCell(withIdentifier: "Cell", for: indexPath! as IndexPath) as! FindAPartyCell
let party:PFObject = self.partyData.object(at: indexPath!.row) as! PFObject
cell.typeOfPartyLabel.alpha = 0
cell.timeOfPartyLabel.alpha = 0
cell.usernameLabel.alpha = 0
var findUser:PFQuery = PFUser.query()!
findUser.whereKey("objectId", equalTo: party.object(forKey: "UserName"))
findUser.findObjectsInBackground {
(objects:[PFObject]?, error: Error?) -> Void in // Changes NSError to Error
if error == nil{
let user:PFUser = (objects as NSArray).lastObject as! PFUser
cell.usernameLabel.text = user.username
UIView.animate(withDuration: 0.5, animations: {
cell.typeOfPartyLabel.alpha = 1
cell.timeOfPartyLabel.alpha = 1
cell.usernameLabel.alpha = 1
})
}
}
return cell
}
There is no need to convert swift native Array type to NSArray to access just lastObject of array you need to simply use last property of native Array instance.
if let user = objects.last {
cell.usernameLabel.text = user.username
}
In Swift use native Array and Dictionary instead of NSArray and NSDictionary. So it is batter if you declare your partyData as [PFObject] instead of NSMutableArray.
I have made a searchbar in my table header view. I actually would not mind having it in my navigation bar, by setting it to: navigationItem.titleView = searchController.searchBar.. The problem is though that when the searchBar is active, the navigation bar is dismissed - including the searchBar, So you cannot see what you are searching for?
How can I change that? Here is my complete searchBar code:
import UIKit
import FirebaseDatabase
import FirebaseAuth
import FBSDKCoreKit
import FirebaseStorage
class SearchTableViewController: UITableViewController, UISearchResultsUpdating {
#IBOutlet var searchUsersTableView: UITableView!
let searchController = UISearchController(searchResultsController: nil)
var usersArray = [NSDictionary?]()
var filteredUsers = [NSDictionary?]()
let databaseRef = FIRDatabase.database().reference()
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
//tableView.tableHeaderView = searchController.searchBar
navigationItem.titleView = searchController.searchBar
searchController.searchBar.placeholder = "Søg"
searchController.searchBar.setValue("Annuller", forKey:"_cancelButtonText")
let cancelButtonAttributes: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as? [String : AnyObject], forState: UIControlState.Normal)
databaseRef.child("UserInformation").queryOrderedByChild("userName").observeEventType(.ChildAdded, withBlock: { (snapshot) in
self.usersArray.append(snapshot.value as? NSDictionary)
self.searchUsersTableView.insertRowsAtIndexPaths([NSIndexPath(forRow: self.usersArray.count-1, inSection: 0)], withRowAnimation: .Automatic)
}) { (error) in
print(error.localizedDescription)
}
}
override func viewWillAppear(animated: Bool) {
if let user = FIRAuth.auth()?.currentUser {
let userId = user.uid
FIRDatabase.database().reference().child("Users").child(userId).child("NotificationBadge").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
// Get user value
let value = snapshot.value as? NSDictionary
let badgesNumber = value?["numberOfBadges"] as! Int?
if badgesNumber != nil {
self.tabBarController?.tabBar.items?[3].badgeValue = String(badgesNumber!)
} else {
self.tabBarController?.tabBar.items?[3].badgeValue = nil
}
// ...
}) { (error) in
print(error.localizedDescription)
}
}
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showProfile" {
if let nextVC = segue.destinationViewController as? theProfileTableViewController {
nextVC.viaSegue = sender! as! String
}
}
}
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 {
// #warning Incomplete implementation, return the number of rows
if searchController.active && searchController.searchBar.text != "" {
return filteredUsers.count
}
return usersArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:SearchTableViewCell = tableView.dequeueReusableCellWithIdentifier("searchCell", forIndexPath: indexPath) as! SearchTableViewCell
let user: NSDictionary?
if searchController.active && searchController.searchBar.text != "" {
user = filteredUsers[indexPath.row]
} else {
user = self.usersArray[indexPath.row]
}
cell.nameLabel.text = user?["userName"] as? String
let profileUserIDPic = user?["usersUID"] as? String
let storage = FIRStorage.storage()
// Refer to your own Firebase storage
let storageRef = storage.referenceForURL("gs://bigr-1d864.appspot.com")
let profilePicRef = storageRef.child(profileUserIDPic!+"/profile_pic.jpg")
// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
profilePicRef.dataWithMaxSize(1 * 300 * 300) { (data, error) -> Void in
if (error != nil) {
// Uh-oh, an error occurred!
print("Unable to download image")
cell.profilePic.image = UIImage(named: "profile.png")
cell.profilePic.layer.cornerRadius = cell.profilePic.frame.size.width/2
cell.profilePic.clipsToBounds = true
} else {
// Data for "images/island.jpg" is returned
// ... let islandImage: UIImage! = UIImage(data: data!)
if (data != nil){
cell.profilePic.image = UIImage(data: data!)
cell.profilePic.layer.cornerRadius = cell.profilePic.frame.size.width/2
cell.profilePic.clipsToBounds = true
}
}
}
return cell
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
// update something
filterContent(self.searchController.searchBar.text!)
}
func filterContent(searchText: String) {
self.filteredUsers = self.usersArray.filter{ user in
let username = user!["userName"] as? String
return (username?.lowercaseString.containsString(searchText.lowercaseString))!
}
self.tableView.reloadData()
}
}
When going to the search page it looks like this (because I added the insets
When searching for a user it looks like this
When having click a user and returned to search it looks like this
In my app I have two table views. The first table view has a set number of cells. These cells will always be the same and will never change The above table view will always have the 4 cells and never more. On my server I have my API which has routes for each of these cells.
For example:
GET - myAPI/Air
GET - myAPI/history
GET - myAPI/train
GET - myAPI/taxi
And each routes send backs different data
mainTablewView:
import UIKit
enum NeededAPI {
case Air
case History
case Train
case Taxi
}
class mainTableViewController : UITableViewController {
struct WeatherSummary {
var id: String
}
var testArray = NSArray()
var manuArray = NSArray()
// Array of sector within our company
var selectSector: [String] = ["Air", "History","Train","Taxi"]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.rowHeight = 80.0
}
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 self.selectSector.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("sectorList", forIndexPath: indexPath)
// Configure the cell...
if selectSector.count > 0 {
cell.textLabel?.text = selectSector[indexPath.row]
}
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "AirSegue"){
if let destination = segue.destinationViewController as? AirTableViewController {
let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow!
if let row:Int = indexPath.row {
destination.apiThatNeedsToBeCalled = .Air
}
}
}
if (segue.identifier == "HistorySegue"){
if let destination = segue.destinationViewController as? HistoryTableViewController {
let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow!
if let row:Int = indexPath.row {
destination.apiThatNeedsToBeCalled = .History
}
}
}
if (segue.identifier == "TrainSgue"){
if let destination = segue.destinationViewController as? TrainTableViewController {
let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow!
if let row:Int = indexPath.row {
destination.apiThatNeedsToBeCalled = .Train
}
}
}
if (segue.identifier == "TaxiSegue"){
if let destination = segue.destinationViewController as? TaxiTableViewController {
let indexPath:NSIndexPath = self.tableView.indexPathForSelectedRow!
if let row:Int = indexPath.row {
destination.apiThatNeedsToBeCalled = .Taxi
}
}
}
}
}
and Post
import Foundation
class Post : CustomStringConvertible {
var userId:Int
var title: String
init(userid:Int , title:String){
self.userId = userid
self.title = title
}
var description : String { return String(userId) }
}
When user selects cell you set the correct value for the apiThatNeedsToBeCalled. Once you do this, code inside the didSet will get executed and it should call the function which calls the appropriate API.
to other tableView :
import UIKit
class AirTableViewController: UITableViewController {
var postCollection = [Post]()
var apiThatNeedsToBeCalled:NeededAPI = .Air {
didSet {
//check which API is set and call the function which will call the needed API
AirLine()
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var apiThatNeedsToBeCalled:NeededAPI = .Air {
didSet {
//check which API is set and call the function which will call the needed API
AirLine()
}
}
func AirLine(){
let url = NSURL(string: "http://jsonplaceholder.typicode.com/posts")
NSURLSession.sharedSession().dataTaskWithURL(url!){[unowned self] (data , respnse , error) in
if error != nil{
print(error!)
}else{
do{
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! [[String:AnyObject]]
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
var newPost = Iduser(id: 0)
for posts in json {
let postObj = Post(userid:posts["userId"] as! Int,title: posts["title"] as! String)
self.postCollection.append(postObj)
}
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}
}catch let error as NSError{
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
print(error.localizedDescription)
let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("Error could not parse JSON:\(jsonStr)")
dispatch_async(dispatch_get_main_queue()) {
let alert = UIAlertController(title: "Alert", message: "Oops! Wrong Details, Try Again", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
}
}
}
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 self.postCollection.count ?? 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("AirCell", forIndexPath: indexPath)
// Configure the cell...
// cell.textLabel?.text = "test"
let weatherSummary = postCollection[indexPath.row]
cell.textLabel?.text = String(weatherSummary.userId)
cell.detailTextLabel?.text = weatherSummary.title
return cell
}
}
mainTableView and Air cell is Ok but when that selected other return The same information Air cell?
Perhaps I'm just missing it, but I can see your creation of the NSURLSession looks fine, but I don't see where you're calling .resume() on that once you've created it. If you don't call .resume() it'll never even perform that URLSession at all. Check the discussion here.
So this is how I'm retrieving all the data and then added a custom button this way :
import UIKit
class userListTableViewController: UITableViewController {
var data:NSMutableArray = NSMutableArray()
func loadData() {
data.removeAllObjects()
var userQuery = PFUser.query()
userQuery?.orderByAscending("createdAt")
userQuery?.findObjectsInBackgroundWithBlock({ (objects, erroe) -> Void in
if let objects = objects {
for object in objects {
if let user = object as? PFUser {
if user.objectId != PFUser.currentUser()?.objectId {
self.data.addObject(object)
}
}
}
}
self.tableView.reloadData()
})
}
override func viewDidLoad() {
super.viewDidLoad()
loadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier("users", forIndexPath: indexPath) as! userListTableViewCell
let userData:PFObject = self.data.objectAtIndex(indexPath.row) as! PFObject
// Usernames and gender..
myCell.fullName.text = userData.objectForKey("fullName") as! String!
myCell.genderLabel.text = userData.objectForKey("gender") as! String!
// Profile pictures..
let profilePics = userData.objectForKey("profilePicture") as! PFFile
profilePics.getDataInBackgroundWithBlock { (data, error) -> Void in
if let downloadedImage = UIImage(data: data!) {
myCell.dp.image = downloadedImage
}
}
myCell.followButtton.removeTarget(nil, action: nil, forControlEvents: UIControlEvents.AllEvents)
myCell.followButtton.addTarget(self, action: "followButtonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
return myCell
}
// IBActions..
func followButtonTapped(sender:AnyObject) {
let buttonPosition = sender.convertPoint(CGPointZero, toView: self.tableView)
let indexPath = self.tableView.indexPathForRowAtPoint(buttonPosition)
if indexPath != nil {
if let cell = self.tableView.cellForRowAtIndexPath(indexPath!) as? userListTableViewCell {
cell.followButtton.setTitle("unfollow", forState: UIControlState.Normal)
var followers:PFObject = PFObject(className: "Followers")
followers["follower"] = PFUser.currentUser()?.objectId
followers["user"] = //*********************** here i want to save the objectId of the user being tapped on. want to get the NSMutableArray index from the indexPath
}
println(indexPath!)
}
}
my problem is there where you see ************************. now like in cellForRowAtIndexPath I've used this to show the data :
let userData:PFObject = self.data.objectAtIndex(indexPath.row) as! PFObject
same like this i want to do it in func followButton(sender:AnyObject).
You should not call self.tableView.reloadData() in the for loop, you should do that only once at the end of the for loop when all the data is loaded.
self.data.objectAtIndex(indexPath.row) this worked.
Hi I am trying to figure out how to make it so that all my data for my timeline can reload on its own. Here is my current code for the whole TimeLineViewController
import UIKit
import CoreData
class TimelineTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate, UIAlertViewDelegate {
var timelineData:NSMutableArray! = NSMutableArray()
override init(style: UITableViewStyle) {
super.init(style: style)
// Custom initialization
}
#IBAction func reportButton(sender: AnyObject) {
performSegueWithIdentifier("reportSegue", sender: self)
}
#IBAction func composeStatus(sender: AnyObject) {
performSegueWithIdentifier("composeSegue", sender:self)
}
#IBAction func logout(sender: AnyObject) {
PFUser.logOut()
var currentUser = PFUser.currentUser() // this will now be nil
performSegueWithIdentifier("logoutSegue", sender:self)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func loadData(){
timelineData.removeAllObjects()
var findTimelineData:PFQuery = PFQuery(className: "woofs")
findTimelineData.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in
if error == nil{
for object in objects{
let woofs:PFObject = object as PFObject
self.timelineData.addObject(woofs)
}
let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
self.timelineData = NSMutableArray(array: array)
self.tableView.reloadData()
}
}
}
override func viewDidAppear(animated: Bool) {
self.loadData()
}
func refresh(sender:AnyObject)
{
// Updating your data here...
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
}
override func viewDidLoad() {
super.viewDidLoad()
var statusBarHidden: Bool
/*var newFeatureAlert:UIAlertController = UIAlertController(title: "Attention", message: "New feature added. You can now Report content that you find offensive. Just tap on Report to get the instructions on how to.", preferredStyle: UIAlertControllerStyle.Alert)
newFeatureAlert.addAction(UIAlertAction(title: "AWESOME!", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(newFeatureAlert, animated: true, completion: nil)*/
self.refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
UITextView.appearance().tintColor = UIColor.blackColor().colorWithAlphaComponent(1.0)
UITextView.appearance().backgroundColor = UIColor.clearColor().colorWithAlphaComponent(0.4)
self.tableView.backgroundView = UIImageView(image: UIImage(named: "hdwallpaper"))
}
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:PAHTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PAHTableViewCell
cell.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
let woofers:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
cell.pahTextView.alpha = 0
cell.timestampLabel.alpha = 0
cell.usernameLabel.alpha = 0
cell.pahTextView.text = woofers.objectForKey("content") as String
var dataFormatter:NSDateFormatter = NSDateFormatter()
dataFormatter.dateFormat = "dd-MM-yyyy HH:mm"
cell.timestampLabel.text = dataFormatter.stringFromDate(woofers.createdAt)
var findwoofers:PFQuery = PFUser.query()
findwoofers.whereKey("objectId", equalTo: woofers.objectForKey("woofers").objectId)
findwoofers.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!)->Void in if error == nil{
if let user:PFUser = (objects as NSArray).lastObject as? PFUser{
cell.usernameLabel.text = user.username
cell.timestampLabel.alpha = 0
cell.profileImageView.alpha = 0
cell.pahTextView.alpha = 0
if let profileImage = user["profileImage"] as? PFFile{
profileImage.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
let image = UIImage(data:imageData)
cell.profileImageView.image = image
}else{
let image = UIImage(named: "BLUEPAW")
}
}
}
}
}
UIView.animateWithDuration(1.0, animations:{
cell.profileImageView.alpha = 1
cell.usernameLabel.alpha = 2
cell.timestampLabel.alpha = 4
cell.pahTextView.alpha = 3
})
}
return cell
}
let me know what I need to change to make this work. Thank You.