İ dont know English very well. İ try to explain this error with code.
DBContextDelagate
import Foundation
import UIKit
import Parse
@objc protocol DBContextDelegate {
optional func SingUpResponse(result : Bool)
optional func LoginResponse(result : Bool)
optional func GetUsersInfoResponse(result : AnyObject)
optional func GetUsersInfo(result : Bool)
optional func GetDataResponse(result : Bool)
}
class DBContext : UIViewController{
var delegate : DBContextDelegate?
func SingUp(user : User) {
let pfUser = PFUser()
pfUser.username = user.userUserName
pfUser.password = user.userPassword
pfUser.email = user.userEmail
pfUser["fullname"] = user.userFullName
let profilePhotoData = UIImageJPEGRepresentation(user.userProfilePhoto, 0.5)
let profilePhotoFile = PFFile(name: "profilePhoto.jpg", data: profilePhotoData!)
pfUser["profilePhoto"] = profilePhotoFile
pfUser.signUpInBackgroundWithBlock { (success:Bool, error:NSError?) -> Void in
if (error != nil) {
self.delegate?.SingUpResponse!(false)
print(error)
}else {
self.delegate?.SingUpResponse!(true)
}
}
}
func Login(user:User){
PFUser.logInWithUsernameInBackground(user.userUserName, password:user.userPassword) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
self.delegate?.LoginResponse!(true)
} else {
self.delegate?.LoginResponse!(false)
}
}
}
func GetUsersInfo(){
var userArray = Array<UserInfo>()
let query = PFUser.query()
query!.findObjectsInBackgroundWithBlock {
(objects:[PFObject]?, error:NSError?) -> Void in
if error == nil {
if let objects = objects {
for object in objects {
let user = UserInfo()
user.userID = object.objectId!
user.userUserName = object["username"] as? String
user.userFullName = object["fullname"] as? String
user.userEmail = object["email"] as? String
let userPhoto = object["profilePhoto"] as! PFFile
userPhoto.getDataInBackgroundWithBlock { (data:NSData?, error:NSError?) -> Void in
user.userProfilePhoto = UIImage(data: data!)!
}
userArray.append(user)
print(userArray.count)
}
self.delegate?.GetUsersInfoResponse!(userArray)
}
self.delegate?.GetDataResponse!(true)
} else {
self.delegate?.GetDataResponse!(false)
}
}
}
}
And HomeVC CollectionView
import UIKit
import Parse
class homeVC: UICollectionViewController,DBContextDelegate{
var userInfoArray : [UserInfo] = [UserInfo]()
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = .whiteColor()
self.navigationItem.title = PFUser.currentUser()?.username?.uppercaseString
Singleton.sharedInstance.dbContext.delegate = self
Singleton.sharedInstance.dbContext.GetUsersInfo()
print("ViewDidLoad: (userInfoArray.count)")
}
func GetUsersInfoResponse(result: AnyObject) {
userInfoArray = result as! [UserInfo]
}
func GetDataResponse(result: Bool) {
if result == true {
}else {
print("Olmadı")
}
}
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: "HeaderView", forIndexPath: indexPath) as! headerVC
//I have problem with this line index out of range
let user = userInfoArray[indexPath.row]
header.fullnameLbl.text = user.userFullName
header.editProfileButton.setTitle("Profili Düzenle", forState: UIControlState.Normal)
return header
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 0
}
}
Aucun commentaire:
Enregistrer un commentaire