2015-05-24 3 views
1

ошибка «NSArray» в части позволяют пользователю я использую новый swift1.2 пожалуйста, помогите [AnyObject] не конвертируется в NSArray'[AnyObject]?' не конвертируется в

var PostData:NSMutableArray = NSMutableArray() 

func loadData(){ 
    PostData.removeAllObjects() 

    var findPostData:PFQuery = PFQuery(className: "Posts") 

    findPostData.findObjectsInBackgroundWithBlock{ 
     (objects, error) -> Void in 

     if error == nil { 
      for object in objects! { 
       let post:PFObject = object as! PFObject 
       self.PostData.addObject(post) 
      } 

      let array:NSArray = self.PostData.reverseObjectEnumerator().allObjects 
      self.PostData = NSMutableArray(array: array) 

      self.tableView.reloadData() 
     } 
    } 
} 

Ниже cellForRowAtIndexPath метод

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let postcell = tableView.dequeueReusableCellWithIdentifier("Postcell", forIndexPath: indexPath) as! PostscaamTableViewCell 

    let post:PFObject = self.PostData.objectAtIndex(indexPath.row) as! PFObject 

    postcell.postTimelineTextView.alpha = 0 
    postcell.timeStamp.alpha = 0 
    postcell.usernameLabel3.alpha = 0 

    postcell.postTimelineTextView.text = post.objectForKey("Content") as! String 

    var dateFormatter:NSDateFormatter = NSDateFormatter() 
    dateFormatter.dateFormat = "dd-mm-yyyy HH:mm" 
    postcell.timeStamp.text = dateFormatter.stringFromDate(post.createdAt!) 

    var findPostedBy:PFQuery = PFUser.query()! 

    findPostedBy.whereKey("objectId", equalTo: post.objectForKey("Postedby")!) 

    findPostedBy.findObjectsInBackgroundWithBlock{ 
     (objects, error)->Void in 
     if error == nil { 
      let USER:PFUser = (objects as NSArray).lastObject as! PFUser 
       postcell.usernameLabel3.text = USER.username 

      UIView.animateWithDuration(0.2, animations: { 
       postcell.postTimelineTextView.alpha = 1 
       postcell.timeStamp.alpha = 1 
       postcell.usernameLabel3.alpha = 1 

      }) 
     } 
    } 

    return postcell 
} 

ответ

0

Попробуйте принудительное понижение, например (objects as! NSArray).

+0

[AnyObject] к несвязанной типа «NSArray» всегда терпит неудачу – motivation1

1

Попробуйте вот так.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let postcell = tableView.dequeueReusableCellWithIdentifier("Postcell", forIndexPath: indexPath) as! PostscaamTableViewCell 

    let post:PFObject = self.PostData.objectAtIndex(indexPath.row) as! PFObject 

    postcell.postTimelineTextView.alpha = 0 
    postcell.timeStamp.alpha = 0 
    postcell.usernameLabel3.alpha = 0 

    postcell.postTimelineTextView.text = post.objectForKey("Content") as! String 

    var dateFormatter:NSDateFormatter = NSDateFormatter() 
    dateFormatter.dateFormat = "dd-mm-yyyy HH:mm" 
    postcell.timeStamp.text = dateFormatter.stringFromDate(post.createdAt!) 

    var findPostedBy:PFQuery = PFUser.query()! 

    findPostedBy.whereKey("objectId", equalTo: post.objectForKey("Postedby")!) 

    findPostedBy.findObjectsInBackgroundWithBlock{ 
     (objects, error) -> Void in 
     if error == nil { 
      if let users : [PFUser] = objects as? [PFUser] where users.count > 0 { 
      let USER:PFUser = users.last! 
       postcell.usernameLabel3.text = USER.username 


       UIView.animateWithDuration(0.2, animations: { 
        postcell.postTimelineTextView.alpha = 1 
        postcell.timeStamp.alpha = 1 
        postcell.usernameLabel3.alpha = 1 

       }) 
      } 
     } 
    } 
    return postcell 
} 
+0

благодаря человеку она работает nowq – motivation1

+0

Если он работает, принимает ответ. Это поможет другим в качестве правильного ответа. – Amit89

+0

@ Amit89 еще одна проблема: мои данные не отображаются, я пытался исправить это, но ничего не происходит, и ошибка не возникает. Я думаю, что в swift 1.2 существует другой способ отображения данных из parse – motivation1

Смежные вопросы