UIScrollView Crashing after ReloadData - ios

i have ScrollView in every row of tableView. i am assigning different tag to it.
it works perfectly for the first time. when change data in array and make ReloadData App Crashes.
Error is like
fatal error: unexpectedly found nil while unwrapping an Optional value
Piece of code
cell = tableView.dequeueReusableCell(withIdentifier: "ContentCell", for: indexPath)
let lblName = (cell.viewWithTag(31)! as! UILabel)
let lblSubmited = (cell.viewWithTag(32)! as! UILabel)
let lblFrom = (cell.viewWithTag(33)! as! UILabel)
let lblTo = (cell.viewWithTag(34)! as! UILabel)
let lblTotalHours = (cell.viewWithTag(35)! as! UILabel)
let lblapprove = (cell.viewWithTag(36)! as! UILabel)
lblName.text = dict.object(forKey: "name") as? String
lblSubmited.text = dict.object(forKey: "submitted") as? String
lblFrom.text = dict.object(forKey: "from") as? String
lblTo.text = dict.object(forKey: "to") as? String
lblTotalHours.text = dict.object(forKey: "tot") as? String
lblapprove.text = "Pending"
let scrollView:UIScrollView!
if(flag.object(at: indexPath.row) as! String == "0"){
scrollView = (cell.viewWithTag(3)! as! UIScrollView)
scrollView.tag = ((100 * indexPath.row)+1)
flag.replaceObject(at: indexPath.row, with: "1")
}
else{
scrollView = (cell.viewWithTag(((100 * indexPath.row)+1))! as! UIScrollView)
}
scrollView.delegate = self
scrollView.showsHorizontalScrollIndicator = false
let viewContent = (cell.viewWithTag(1000)!)
let btApprove = UIButton(frame: CGRect(x: 704.0, y: 10.0, width: 40.0, height: 40.0))
let btReject = UIButton(frame: CGRect(x: 788.0, y: 10.0, width: 40.0, height: 40.0))
let btDetail = UIButton(frame: CGRect(x: 860.0, y: 10.0, width: 40.0, height: 40.0))
btApprove.addTarget(self, action: #selector(self.approvePressedAction), for: .touchUpInside)
btReject.addTarget(self, action: #selector(self.rejectPressedAction), for: .touchUpInside)
btDetail.addTarget(self, action: #selector(self.detailPressedAction), for: .touchUpInside)
viewContent.addSubview(btApprove)
viewContent.addSubview(btReject)
viewContent.addSubview(btDetail)
return cell
error comes in
scrollView = (cell.viewWithTag(3)! as! UIScrollView)
line and crashes after reloadData. Any Solution?

Seems like you are forcing a lot of optionals to un-wrap, maybe check them first before trying to use them.
I have no idea what your logic is doing, but to run some checks on the specific line that crashes try something like this.
var scrollView:UIScrollView!
if(flag.object(at: indexPath.row) as! String == "0"){
if let view = cell.viewWithTag(3) {
if let sv = view as? UIScrollView {
scrollView = sv
scrollView.tag = ((100 * indexPath.row)+1)
flag.replaceObject(at: indexPath.row, with: "1")
} else {
print("view found with tag 3 but it's not a scrollview")
}
} else {
print("no view found with tag 3")
}
} else {
scrollView = (cell.viewWithTag(((100 * indexPath.row)+1))! as! UIScrollView)
}

Related

UITapGestureRecognizer not working until I scroll all the way to the bottom

I have added a UITapGestureRecognizer to a label in a UITableViewCell, however the click only works after I scroll to the bottom of the table.
Once I scroll to the bottom the tap works perfectly and performs the segue, but until I do, it does not call the function.
I have verified that the if statement does evaluate as true before I scroll, so the recognizer is there, but it just doesn't work.
Any ideas as to why would be greatly appreciated.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
for viewToRemove in cell.subviews {
viewToRemove.removeFromSuperview();
}
let result = self.ResultArray[indexPath.row] as! NSDictionary;
let width = self.frame.width;
let rawTime = result["LogInDTM"] as? String;
let rawUNIT = result[“unit”] as? String;
let rawPersonID = result["PERS_ID"] as? String;
let rawName = result["PERS_NAME"] as? String;
let rawVehicle = result["Vehicle_ID"] as? String;
let rawCall = result["CALL_NO"] as? String;
var CleanVehicle = ""
if let tmpVehicle = rawVehicle {
CleanVehicle = tmpVehicle
}
var CleanCall = ""
if let tmpCall = rawCall {
CleanCall = tmpCall
}
var CleanUnit = ""
if let tmpUnit = rawUNIT {
CleanUnit = tmpUnit
}
//print(result);
let cellView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: 30));
cellView.backgroundColor = .black;
cellView.layer.cornerRadius = 5;
cellView.layer.masksToBounds = true;
let UnitLabel = UILabel(frame: CGRect(x: 2, y: 0, width: width*0.15, height: 30));
UnitLabel.textColor = .white;
UnitLabel.layer.borderWidth = 1.0;
UnitLabel.layer.borderColor = self.configuration.SOOrange.cgColor;
UnitLabel.text = " "+CleanUnit;
UnitLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight(rawValue: 400));
UnitLabel.adjustsFontSizeToFitWidth = true;
cellView.addSubview(UnitLabel);
let SubjectLabel = UILabel(frame: CGRect(x: (width*0.15)+2, y: 0, width: width*0.4, height: 30));
SubjectLabel.textColor = .white;
SubjectLabel.layer.borderWidth = 1.0;
SubjectLabel.layer.borderColor = self.configuration.SOOrange.cgColor;
SubjectLabel.text = " "+rawName!;
SubjectLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight(rawValue: 400));
SubjectLabel.adjustsFontSizeToFitWidth = true;
cellView.addSubview(SubjectLabel);
let VehicleLabel = UILabel(frame: CGRect(x: (width*0.55)+2, y: 0, width: width*0.2, height: 30));
VehicleLabel.textColor = .white;
VehicleLabel.layer.borderWidth = 1.0;
VehicleLabel.layer.borderColor = self.configuration.SOOrange.cgColor;
VehicleLabel.text = " "+CleanVehicle;
VehicleLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight(rawValue: 400));
VehicleLabel.adjustsFontSizeToFitWidth = true;
cellView.addSubview(VehicleLabel);
let CallLabel = UILabel(frame: CGRect(x: (width*0.75)+2, y: 0, width: width*0.24, height: 30));
CallLabel.textColor = .white;
CallLabel.layer.borderWidth = 1.0;
CallLabel.layer.borderColor = self.configuration.SOOrange.cgColor;
CallLabel.text = " "+CleanCall;
CallLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight(rawValue: 400));
CallLabel.adjustsFontSizeToFitWidth = true;
if(CleanCall != ""){
print(CleanCall);
let callTap = UITapGestureRecognizer(target: self, action: #selector(self.openCall(_:)))
CallLabel.isUserInteractionEnabled = true
CallLabel.addGestureRecognizer(callTap)
}
cellView.addSubview(CallLabel);
cell.addSubview(cellView);
return cell;
}

iOS UITableView is not selectable when it is scrolled

I am facing this issue and I am not getting any clear answer. I have a UITableView which works fine when it loads for the first time but when it scrolls, it is not selectable, didSelectRowAtIndexPath never gets a call. Also I've button in my cell, it's not clickable either. But I can still scroll tableview. This is my code :
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell : ContactTableViewCell = tableView.dequeueReusableCell(withIdentifier: "ContactCell") as! ContactTableViewCell
cell.selectionStyle = .none
cell.backgroundColor = UIColor.clear
cell.delegate = self
let randomNumber = Int(arc4random_uniform(UInt32(colorsArray!.count)))
if(!shouldUseFilteredResults) {
cell.setFilteredContents(_with: addressBookArray![indexPath.row], theme: themeStyle!, randomColor: colorsArray![randomNumber])
}
else {
cell.setFilteredContents(_with: filteredAddressBook[indexPath.row], theme: themeStyle!, randomColor: colorsArray![randomNumber])
cell.contactNameLabel.attributedText = self.highlightSearchResult(resultString: cell.contactNameLabel.text!)
}
return cell
}
In cell :
public func setFilteredContents (_with contact : [String : Any], theme : Theme, randomColor : UIColor)
{
contactDictionary = contact;
contactNameLabel.text = String(describing: contact["FullName"]!)
self.setTheme(theme: theme, randomColor: randomColor)
if (contact["ImageDataString"] != nil)
{
let imageData = Data(base64Encoded: contact["ImageDataString"] as! String)
let image = UIImage(data: imageData!)
let imageView = UIImageView(frame: thumbnailView.bounds)
imageView.contentMode = .scaleAspectFill
imageView.layer.masksToBounds = true
imageView.layer.cornerRadius = CGFloat(imageView.height()/2)
imageView.image = image
thumbnailView.addSubview(imageView)
}
else {
self.setThumbnail(fullName: contactNameLabel.text!)
}
}
private func setThumbnail(fullName : String)
{
let vibrancy = UIVibrancyEffect(blurEffect: UIBlurEffect(style: .light))
let backgroundView = UIVisualEffectView(effect: vibrancy)
backgroundView.frame = thumbnailView.bounds
thumbnailView.addSubview(backgroundView)
let thumbNailLabel = UILabel(frame: thumbnailView.bounds)
thumbNailLabel.font = UIFont.systemFont(ofSize: 13)
thumbNailLabel.textColor = UIColor.white
thumbNailLabel.textAlignment = .center
var initialLettersString = String()
let wordsArray = fullName.components(separatedBy: NSCharacterSet.whitespaces)
for word in wordsArray
{
if(word != "")
{
initialLettersString.append(String(describing: word.characters.first!))
}
}
if(initialLettersString.characters.count == 1)
{
initialLettersString = String(initialLettersString[..<initialLettersString.index(initialLettersString.startIndex, offsetBy: 1)]).uppercased()
}
if(initialLettersString.characters.count > 1)
{
initialLettersString = String(initialLettersString[..<initialLettersString.index(initialLettersString.startIndex, offsetBy: 2)]).uppercased()
}
thumbNailLabel.text = initialLettersString as String
backgroundView.contentView.addSubview(thumbNailLabel)
}
private func setTheme(theme : Theme, randomColor : UIColor)
{
let isContactFavorite = contactDictionary?[Constants.TTCIsContactFavoriteKey] as? Bool
thumbnailView.backgroundColor = randomColor
if(theme == Theme.Light)
{
contactNameLabel.textColor = UIColor.black
lineView.backgroundColor = UIColor.lightGray
if(!isContactFavorite!)
{
favoritesButton.setImage(UIImage(named: "favorite_dark.png"), for: .normal)
}
else
{
favoritesButton.setImage(UIImage(named: "favorite.png"), for: .normal)
}
}
else if(theme == Theme.Dark)
{
contactNameLabel.textColor = UIColor.white
lineView.backgroundColor = UIColor.gray
if(!isContactFavorite!)
{
favoritesButton.setImage(UIImage(named: "favorite_white.png"), for: .normal)
}
else
{
favoritesButton.setImage(UIImage(named: "favorite.png"), for: .normal)
}
}
for view in thumbnailView.subviews
{
view.removeFromSuperview()
}
}
Custom Cell :
What could be the issue?
This may also because of overriding default touch events with UITapRecognizers in the View Hierarchy
Remove any tap recognizers set to to UITableview Parent View
Thanks everyone for help. Issue was with SwipeCellKit which I was using for CustomCell. Removing it solved it!
You are doing everything right.
Just check your button frame does lies inside your cell.
Some times your cell height is less and button is outside the bounds of cell.

Reuse Identifier on iCarousel

I am trying to build a carousel on my app based on this project, https://github.com/nicklockwood/iCarousel, only I am writing it in swift. I have it working correctly, where you can scroll through and tap on the item at index correctly here:
func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
let tempView = UIView(frame: CGRect(x: 0, y: 130, width: 295, height: 300))
let object = self.imageFilesArray.object(at: index) as! PFObject
let imageView = UIImageView()
imageView.frame = CGRect(x: 0, y: 0 , width: 295, height: 295)
imageView.layer.cornerRadius = 15
imageView.layer.masksToBounds = true
let imageFile = object.object(forKey: "Image") as! PFFile
imageFile.getDataInBackground{
(data, error) -> Void in
if error == nil {
}
imageView.image = UIImage(data: data!)
tempView.addSubview(imageView)
}
return tempView
}
func carousel(_ carousel: iCarousel, didSelectItemAt index: Int) {
let cell = carouselView.itemView(at: index)
let object = self.imageFilesArray[index] as! PFObject
if cell?.tag == 0 {
print("open cell")
let moveImg = CGAffineTransform(translationX: 0, y: -100)
UIView.animate(withDuration: 0.4, delay: 0.1, options: [], animations: {
//cell.imageView.transform = moveImg
}, completion: nil)
cell?.tag = 1
} else if cell?.tag == 1 {
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "EventDetailViewController") as! EventDetailViewController
self.present(nextViewController, animated:false, completion:nil)
}
However, what I am trying to do is when I tap the item at index, the imageView transitions on the screen. My issue is that I cannot access that particular cells imageView in order to move it. Does anyone know what I need to change?
You could give your imageView a tag like this:
let imageView = UIImageView()
imageView.frame = CGRect(x: 0, y: 0 , width: 295, height: 295)
imageView.layer.cornerRadius = 15
imageView.layer.masksToBounds = true
imageView.tag = 2
Then you can retrieve the imageView from the cell like this:
if let imageView = cell.viewWithTag(2) as? UIImageView {
imageView.transform = moveImg
}
OR
You could filter through the subviews of the cell and find the first subview that can be cast to a UIImageView. Although this isn't very robust, consider creating a Class and XIB for this cell.
cell.subviews.flatMap { $0 as? UIImageView }.first?.transform = moveImg

Jerking motion after table view is reloaded

I'm getting a weird jerking motion whenever I reload my row and scroll up. It's fine if it's scrolling down, but scrolling back up is causing a horrible jerking effect, rendering the app useless.
I've attached the code for not only the cellforrowatindex path, but the buttons as well.
cell for row:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableViewCell
cell.nopebutton.tag = indexPath.row
cell.nicebutton.tag = indexPath.row
cell.killText.text = object.valueForKey("text") as! String
cell.layoutMargins = UIEdgeInsetsZero
cell.killText.numberOfLines = 0
let score = object.valueForKey("count") as! Int
cell.count.text = "\(score)"
if cell.count.text == "\(0)"
{
cell.count.textColor = UIColor.grayColor()
}
if cell.count.text > "\(0)"
{
cell.count.textColor = UIColor(red: 42.0/255, green: 204.0/255, blue: 113.0/255, alpha: 1)
}
if cell.count.text < "\(0)"
{
cell.count.textColor = UIColor(red: 231.0/255, green: 76.0/255, blue: 50.0/255, alpha: 1)
}
if cell.count.text == "\(50)"
{
cell.count.textColor = UIColor(red: 249.0/255, green: 191.0/255, blue: 59.0/255, alpha: 1)
}
if let dict : NSDictionary = NSUserDefaults.standardUserDefaults().objectForKey("userNiceNopeDictionary") as? NSDictionary {
cell.nicebutton.enabled = true
cell.nopebutton.enabled = true
if let nice = dict[object.objectId] as? Bool{
if nice {
cell.nicebutton.enabled = false
}
else {
cell.nopebutton.enabled = false
}
}
}
let dateUpdated = object.createdAt as NSDate
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "h:mm a"
cell.time.text = (NSString(format: "%#", dateFormat.stringFromDate(dateUpdated)) as String) as String
let replycnt = object.objectForKey("replies") as! Int
if cell.count.text == "\(-10)"
{
object.deleteInBackground()
}
return cell
}
buttons
#IBAction func topButton(sender: AnyObject) {
var button = sender as! UIButton
// var view = button.superview
//
// var otherButton = view?.viewWithTag(102) as! UIButton
// var label = button.superview!.viewWithTag(110) as! UILabel
// otherButton.enabled = true
// button.enabled = false
var rowNumber = button.tag
var mutableDict = NSMutableDictionary()
if let dict = NSUserDefaults.standardUserDefaults().objectForKey("userNiceNopeDictionary") {
mutableDict = dict.mutableCopy() as! NSMutableDictionary
}
let obj = self.objects[rowNumber] as! PFObject
mutableDict.setValue(true, forKey: obj.objectId)
NSUserDefaults.standardUserDefaults().setObject(mutableDict, forKey: "userNiceNopeDictionary")
NSUserDefaults.standardUserDefaults().synchronize()
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
object.incrementKey("count")
//label.text = object.objectForKey("count") as! String
// self.tableView.reloadData()
object.save()
self.tableView.reloadRowsAtIndexPaths([hitIndex!], withRowAnimation: UITableViewRowAnimation.None)
}
#IBAction func bottomButton(sender: AnyObject) {
var button = sender as! UIButton
var rowNumber = button.tag
var mutableDict = NSMutableDictionary()
if let dict = NSUserDefaults.standardUserDefaults().objectForKey("userNiceNopeDictionary") {
mutableDict = dict.mutableCopy() as! NSMutableDictionary
}
let obj = self.objects[rowNumber] as! PFObject
mutableDict.setValue(false, forKey: obj.objectId)
NSUserDefaults.standardUserDefaults().setObject(mutableDict, forKey: "userNiceNopeDictionary")
NSUserDefaults.standardUserDefaults().synchronize()
let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
let object = objectAtIndexPath(hitIndex)
object.incrementKey("count", byAmount: -1)
self.tableView.reloadRowsAtIndexPaths([hitIndex!], withRowAnimation: UITableViewRowAnimation.None)
object.save()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "killDetail"){
let indexPath = self.tableView.indexPathForSelectedRow()
let obj = self.objects[indexPath!.row] as! PFObject
let detailVC = segue.destinationViewController as! DetailViewController
detailVC.kill = obj
}
}
}
I'm under the impression that there's an issue in my heights so I've included that code as well.
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.separatorInset = UIEdgeInsetsZero
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0)
self.tableView.separatorColor = UIColor(red: 236.0/255, green: 240.0/255, blue: 241.0/255, alpha: 1)
navigationController?.tabBarController?.tabBar.hidden = true
tabBarController?.tabBar.hidden = true
self.tableView.estimatedRowHeight = 60
self.tableView.rowHeight = UITableViewAutomaticDimension
locationManager.desiredAccuracy = 1000
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
I can't for the life of me figure out what's going on causing this jerk. Like I said I think it might have to do with the automaticdimension in the row height, but when I change that the issue is still apparent.
Don't read that dictionary from user defaults every time you dequeue a cell. Do it once, outside of tableView(cellForRowAtIndexPath:. Do it in viewDidLoad or something. Picking out an element from the dictionary once it's in memory is fine though... You just don't want to read from disk (or flash, I guess) every time a cell is dequeued.
If the dictionary is being changed, for any reason, in other places and you want to maintain a consistent state, read the dictionary in once and just pass it around between controllers/view controllers (through, e.g. prepareForSegue) and write it to user defaults when it's changed.
The date formatter is probably not that big or complex of an object to make, but you only need to make one once, and then can reuse it, so I suggest you only create one once too.
edit: If you have a problem just scrolling up, it could be that the estimated row height doesn't match the actual row height. Try removing the estimated height.

UITableview load cell longtime Swift - Need advise tuning

Please kindly refer code in attach and refer in the image as well. I need your advise how can I make quicker for loading
http://imageshack.com/a/img901/7079/mOQkum.png
http://imageshack.com/a/img909/2775/E2zTKs.png
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell {
let wishRow = self.wishDataList.objectAtIndex(indexPath!.row) as! NSMutableArray
println(userImageList.count)
switch (wishRow).count{
case 4:
let cell:WishHeaderTableViewCell = tableView!.dequeueReusableCellWithIdentifier("CellHeader", forIndexPath: indexPath!) as! WishHeaderTableViewCell
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let dateFormatter = NSDateFormatter()
cell.LblCity.text = wishRow[1] as? String
cell.ImgAddWish.layer.cornerRadius = 20
cell.ImgAddWish.clipsToBounds = true
cell.ImgAddWish.autoresizesSubviews = false
// cell.ImageViewTripOwner.layer.cornerRadius = 20
// cell.ImageViewTripOwner.clipsToBounds = true
cell.ImageViewTripOwner.autoresizesSubviews = false
for object in self.userImageList{
if object[0] as? String == (wishRow[3] as? PFUser)?.objectId{
cell.ImageViewTripOwner.image = UIImage(data: (object[1] as! PFFile).getData()!)
//SharedFunction.imageResize(UIImage(data: (object[1] as PFFile).getData())!, sizeChange: CGSize(width: 40, height: 40))
}
}
})
return cell
default:
let cell:WishItemTableViewCell = tableView!.dequeueReusableCellWithIdentifier("CellItem", forIndexPath: indexPath!) as! WishItemTableViewCell
dispatch_async(dispatch_get_main_queue(), { () -> Void in
cell.LblItemName.text = wishRow[5] as? String
cell.ImgItem.image = wishRow[7] as? UIImage
//UIImage(data: (wishRow[7] as PFFile).getData())
//SharedFunction.imageResize(UIImage(data: (wishRow[7] as PFFile).getData())!, sizeChange: CGSize(width: 40, height: 40))
cell.ImgRequestorItem.layer.cornerRadius = 10
cell.ImgRequestorItem.clipsToBounds = true
cell.ImgRequestorItem.autoresizesSubviews = false
cell.ImgRequestorItem.backgroundColor = UIColor.whiteColor()
for object in self.userImageList{
if object[0] as? String == wishRow[8] as? String{
let realImage = UIImageView(frame: CGRect(x: 1.5, y: 1.5, width: 17, height: 17))
realImage.layer.cornerRadius = 8.5
realImage.clipsToBounds = true
dispatch_async(dispatch_get_main_queue(), { () -> Void in
realImage.image = UIImage(data: (object[1] as! PFFile).getData()!)
})
//SharedFunction.imageResize(UIImage(data: (object[1] as PFFile).getData())!, sizeChange: CGSize(width: 17, height: 17))
cell.ImgRequestorItem.addSubview(realImage)
}
}
cell.ImgBackgroundTick.layer.cornerRadius = 7.5
cell.ImgBackgroundTick.clipsToBounds = true
cell.ImgBackgroundTick.autoresizesSubviews = false
cell.ImgBackgroundTick.backgroundColor = UIColor.whiteColor()
let realImage = UIImageView(frame: CGRect(x: 1.5, y: 1.5, width: 12, height: 12))
realImage.layer.cornerRadius = 6
realImage.clipsToBounds = true
realImage.backgroundColor = UIColor(red: 0.450, green: 0.419, blue: 0.321 , alpha: 1)
realImage.image = UIImage(named: "ic_tick")
cell.ImgBackgroundTick.addSubview(realImage)
})
return cell
}
}
Wow, why are you using dispatch_async(dispatch_get_main_queue(), { () -> Void in in cell creation? You don't have to. Remove this method so the code should look like the following:
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell {
let wishRow = self.wishDataList.objectAtIndex(indexPath!.row) as! NSMutableArray
println(userImageList.count)
switch (wishRow).count{
case 4:
let cell = tableView!.dequeueReusableCellWithIdentifier("CellHeader", forIndexPath: indexPath!) as! WishHeaderTableViewCell
let dateFormatter = NSDateFormatter()
cell.LblCity.text = wishRow[1] as? String
cell.ImgAddWish.layer.cornerRadius = 20
cell.ImgAddWish.clipsToBounds = true
cell.ImgAddWish.autoresizesSubviews = false
// cell.ImageViewTripOwner.layer.cornerRadius = 20
// cell.ImageViewTripOwner.clipsToBounds = true
cell.ImageViewTripOwner.autoresizesSubviews = false
for object in self.userImageList{
if object[0] as? String == (wishRow[3] as? PFUser)?.objectId{
cell.ImageViewTripOwner.image = UIImage(data: (object[1] as! PFFile).getData()!)
//SharedFunction.imageResize(UIImage(data: (object[1] as PFFile).getData())!, sizeChange: CGSize(width: 40, height: 40))
}
}
return cell
default:
let cell = tableView!.dequeueReusableCellWithIdentifier("CellItem", forIndexPath: indexPath!) as! WishItemTableViewCell
cell.LblItemName.text = wishRow[5] as? String
cell.ImgItem.image = wishRow[7] as? UIImage
//UIImage(data: (wishRow[7] as PFFile).getData())
//SharedFunction.imageResize(UIImage(data: (wishRow[7] as PFFile).getData())!, sizeChange: CGSize(width: 40, height: 40))
cell.ImgRequestorItem.layer.cornerRadius = 10
cell.ImgRequestorItem.clipsToBounds = true
cell.ImgRequestorItem.autoresizesSubviews = false
cell.ImgRequestorItem.backgroundColor = UIColor.whiteColor()
for object in self.userImageList{
if object[0] as? String == wishRow[8] as? String{
let realImage = UIImageView(frame: CGRect(x: 1.5, y: 1.5, width: 17, height: 17))
realImage.layer.cornerRadius = 8.5
realImage.clipsToBounds = true
dispatch_async(dispatch_get_main_queue(), { () -> Void in
realImage.image = UIImage(data: (object[1] as! PFFile).getData()!)
})
//SharedFunction.imageResize(UIImage(data: (object[1] as PFFile).getData())!, sizeChange: CGSize(width: 17, height: 17))
cell.ImgRequestorItem.addSubview(realImage)
}
}
cell.ImgBackgroundTick.layer.cornerRadius = 7.5
cell.ImgBackgroundTick.clipsToBounds = true
cell.ImgBackgroundTick.autoresizesSubviews = false
cell.ImgBackgroundTick.backgroundColor = UIColor.whiteColor()
let realImage = UIImageView(frame: CGRect(x: 1.5, y: 1.5, width: 12, height: 12))
realImage.layer.cornerRadius = 6
realImage.clipsToBounds = true
realImage.backgroundColor = UIColor(red: 0.450, green: 0.419, blue: 0.321 , alpha: 1)
realImage.image = UIImage(named: "ic_tick")
cell.ImgBackgroundTick.addSubview(realImage)
return cell
}}

Resources