Swift: access UIView children from [Int: UIView]() - swift

I use below code for add view to scrollview and save view to viewAll
var viewAll = [Int: UIView]()
i = 0
for pack in packs as! [[String: AnyObject]] {
let packId = Int(pack["packId"] as! String)
let packTitle = pack["packTitle"] as! String
let view = CategoryClass.createMyClassView()
view.pcId.text = packId
view.pcTitle.text = packTitle
viewAll[i] = view
i = i+1
myScrollView.addSubview(view)
}
It work fine.
Now i want access again to children of view :
for view in viewAll {
view.value.pcId.text = "TEST"
}
This line not work : view.value.pcId.text = "TEST"
CategoryClass:
class CategoryClass: UIView {
#IBOutlet weak var pcId: UILabel!
#IBOutlet weak var pcTitle: UILabel!
class func createMyClassView() -> CategoryClass {
let myClassNib = UINib(nibName: "Category", bundle: nil)
return myClassNib.instantiate(withOwner: nil, options: nil)[0] as! CategoryClass
}
}

This because of casting you need to change
var viewAll = [Int: UIView]()
to
var viewAll = [Int: CategoryClass]()
//
also change this
view.value.pcId.text = "TEST"
to
view.pcId.text = "TEST"

Related

fetched json data Dictionary or array is empty in viewdidload or tableview datasource?

I want to add strings from an array of dictionary from backend.
but it's always empty outside the fetch function
//fetch data
func fetchFaqs(){
let manager = APIManager()
manager.parsingGet(url: BaseURL.faqs) { (JSON, Status) in
if Status {
let dict = JSON.dictionaryObject
let data = dict!["data"] as! [[String:Any]]
self.faqs = data as! [[String : String]]
}
}
}
//Viewdidload
class FaqViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var faqs = [[String:String]]()
var questions = NSMutableArray()
var answers = NSMutableArray()
#IBOutlet var faqsTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
fetchFaqs()
self.faqsTableView.reloadData()
print(faqs)
// faqsTableView.rowHeight = UITableView.automaticDimension
// faqsTableView.estimatedRowHeight = 600
}
}
Reload the tableview inside the api call closure in Main thread
func fetchFaqs(){
let manager = APIManager()
manager.parsingGet(url: BaseURL.faqs) { (JSON, Status) in
if Status {
let dict = JSON.dictionaryObject
let data = dict!["data"] as! [[String:Any]]
self.faqs = data as! [[String : String]]
DispatchQueue.main.async {
self.faqsTableView.reloadData()
}
}
}
}

Want open a plist in NStableview

I've been trying to display a plist file in NSTableView for days. I've read a lot, but so far only found instructions for iOS. My problem is that the individual values ​​are not displayed individually in the NStableView. Only the whole plist file in a cell is always displayed.
I hope someone can help me, because I just can not get any further. I'm still a freshman in Swift.
I uploaded my Plist, if someone can explain me where the error lies.
https://www.dropbox.com/s/1t8c4uldwdtp3wk/Archiv.zip?dl=0
import Cocoa
class ViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
#IBOutlet weak var tableView: NSTableView!
#IBOutlet weak var ntext: NSTextField!
#IBOutlet weak var schwarztext: NSTextField!
#IBOutlet weak var cyantext: NSTextField!
#IBOutlet weak var magentatext: NSTextField!
#IBOutlet weak var gelbtext: NSTextField!
#IBOutlet weak var lightcyantext: NSTextField!
#IBOutlet weak var lightmtext: NSTextField!
var n : String? = nil; // n
var schwarz : String? = nil; // Schwarz
var cyan : String? = nil; // Cyan
var magenta : String? = nil; // Magenta
var gelb : String? = nil; // Gelb
var lightc : String? = nil; // Light Cyan
var lightm : String? = nil; // Light Magenta
let AUTO_PLIST_JOBS_PATH = Bundle.main.path(forResource: "Jobs", ofType: "plist")
let AUTO_PLIST_JOBS_KEY_N = "n" // n
let AUTO_PLIST_JOBS_KEY_SCHWARZ = "schwarz" // Schwarz
let AUTO_PLIST_JOBS_KEY_CYAN = "cyan" // Cyan
let AUTO_PLIST_JOBS_KEY_MAGENTA = "magenta" // Magenta
let AUTO_PLIST_JOBS_KEY_GELB = "gelb" // Gelb
let AUTO_PLIST_JOBS_KEY_LIGHTC = "lightc" // Light Cyan
let AUTO_PLIST_JOBS_KEY_LIGHTM = "lightm" // Light Magenta
var _jobss = [Jobs]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
// Do any additional setup after loading the view.
}
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
//let path = Bundle.main.path(forResource: "Jobs", ofType: "plist")
//let myJobs100 = NSArray(contentsOfFile: path!)
//return myJobs100
let path = Bundle.main.path(forResource: "Jobs", ofType: "plist")
let url = URL(fileURLWithPath: path!)
let data = try! Data(contentsOf: url)
let plist = try! PropertyListSerialization.propertyList(from: data, options: .mutableContainers, format: nil)
let dictArray = plist as! [[String:String]]
return dictArray
}
func allJobss() -> [Jobs]{
if _jobss.count > 0 {
return _jobss
}
if let allDatas = NSArray(contentsOfFile: AUTO_PLIST_JOBS_PATH!) {
for dict in allDatas {
guard let dict = dict as? [String: AnyObject] else {continue}
let jobs = Jobs()
jobs.n = dict[AUTO_PLIST_JOBS_KEY_N] as? String // n
jobs.schwarz = dict[AUTO_PLIST_JOBS_KEY_SCHWARZ] as? String // Schwarz
jobs.cyan = dict[AUTO_PLIST_JOBS_KEY_CYAN] as? String // Cyan
jobs.magenta = dict[AUTO_PLIST_JOBS_KEY_MAGENTA] as? String // Magenta
jobs.gelb = dict[AUTO_PLIST_JOBS_KEY_GELB] as? String // Gelb
jobs.lightc = dict[AUTO_PLIST_JOBS_KEY_LIGHTC] as? String // Light Cyan
jobs.lightm = dict[AUTO_PLIST_JOBS_KEY_LIGHTM] as? String // Light Magenta
_jobss.append(jobs)
}
}
return _jobss
}
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
return 80
}
func numberOfRows(in tableView: NSTableView) -> Int {
return allJobss().count
}
func tableViewSelectionDidChange(_ notification: Notification) {
print(tableView.selectedRow)
let path = Bundle.main.path(forResource: "Jobs", ofType: "plist")
let url = URL(fileURLWithPath: path!)
let data = try! Data(contentsOf: url)
let plist = try! PropertyListSerialization.propertyList(from: data, options: .mutableContainers, format: nil)
let dictArray = plist as! [[String:String]]
// [[String:String]] is equivalent to Array< Dictionary<String, String> >
print(dictArray[tableView.selectedRow]["n"] as Any)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
NSTableview
Plist
I hope someone can help me.
First of all this is Swift. Variable names including underscore characters are ugly and objective-c-ish.
Your workflow is wrong. objectValueFor is called very often (once for each row) and is supposed to return just the object for the given row/column. Reading the same data again and again is horrible.
Load the data once in viewDidLoad and decode the Plist directly into a class. A class is required to be able to bind the values
#objcMembers
class Job : NSObject, Decodable {
dynamic var n, schwarz, cyan, magenta, gelb, lightc, lightm : String
}
#objc dynamic var jobs = [Job]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
// Do any additional setup after loading the view.
let url = Bundle.main.url(forResource: "Jobs", withExtension: "plist")!
let data = try! Data(contentsOf: url)
jobs = try! PropertyListDecoder().decode([Job].self, from: data)
tableView.reloadData()
}
In objectValueFor just return the item for the row
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
return jobs[row]
}
the other delegate methods are
func numberOfRows(in tableView: NSTableView) -> Int {
return jobs.count
}
func tableViewSelectionDidChange(_ notification: Notification) {
let selectedRow = tableView.selectedRow
if selectedRow == -1 {
print("Nothing selected")
} else {
print("Row \(selectedRow) selected")
}
}
You have to bind the values to text fields. Open Interface Builder, ⌃⇧-click on the left-most text field (Table View Cell) in the table view, select Table View Cell, press ⌥⌘7 to open the Bindings Inspector, click on the disclosure triangle below Value, Check the checkbox Bind to Table Cell View, in the Model Key Path text field write objectValue.n. Bind the other text fields in the row to the corresponding properties (objectValue.schwarz etc.).
You can delete
var n : String? = nil; // n
var schwarz : String? = nil; // Schwarz
var cyan : String? = nil; // Cyan
var magenta : String? = nil; // Magenta
var gelb : String? = nil; // Gelb
var lightc : String? = nil; // Light Cyan
var lightm : String? = nil; // Light Magenta
let AUTO_PLIST_JOBS_PATH = Bundle.main.path(forResource: "Jobs", ofType: "plist")
let AUTO_PLIST_JOBS_KEY_N = "n" // n
let AUTO_PLIST_JOBS_KEY_SCHWARZ = "schwarz" // Schwarz
let AUTO_PLIST_JOBS_KEY_CYAN = "cyan" // Cyan
let AUTO_PLIST_JOBS_KEY_MAGENTA = "magenta" // Magenta
let AUTO_PLIST_JOBS_KEY_GELB = "gelb" // Gelb
let AUTO_PLIST_JOBS_KEY_LIGHTC = "lightc" // Light Cyan
let AUTO_PLIST_JOBS_KEY_LIGHTM = "lightm" // Light Magenta
func allJobss() -> [Jobs]{
if _jobss.count > 0 {
return _jobss
}
if let allDatas = NSArray(contentsOfFile: AUTO_PLIST_JOBS_PATH!) {
for dict in allDatas {
guard let dict = dict as? [String: AnyObject] else {continue}
let jobs = Jobs()
jobs.n = dict[AUTO_PLIST_JOBS_KEY_N] as? String // n
jobs.schwarz = dict[AUTO_PLIST_JOBS_KEY_SCHWARZ] as? String // Schwarz
jobs.cyan = dict[AUTO_PLIST_JOBS_KEY_CYAN] as? String // Cyan
jobs.magenta = dict[AUTO_PLIST_JOBS_KEY_MAGENTA] as? String // Magenta
jobs.gelb = dict[AUTO_PLIST_JOBS_KEY_GELB] as? String // Gelb
jobs.lightc = dict[AUTO_PLIST_JOBS_KEY_LIGHTC] as? String // Light Cyan
jobs.lightm = dict[AUTO_PLIST_JOBS_KEY_LIGHTM] as? String // Light Magenta
_jobss.append(jobs)
}
}
return _jobss
}

Show Image on UISplitViewController

I'm a newbie in SWIFT and I do some examples application.
The only thing that I can not get worked is to get my Image displayed on Detail Scene (DetailViewController).
On my MasterViewController file I have this to get my multiData file:
...
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showData" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = self.multiData[indexPath.section][indexPath.row]
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
// Here I get my multiData
func createData() {
var first: [Dictionary<String,String>] = []
var second: [Dictionary<String,String>] = []
dataSections = ["First Data", "Second Data"]
first.append(["name": "someName", "image": "somePngFile", "someData": "someText"])
second.append(["name": "someName", "image": "somePngFile", "someData": "someText"])
multiData = [first, second]
}
DetailViewController:
...
#IBOutlet weak var label: UILabel!
#IBOutlet weak var text: UITextView!
#IBOutlet weak var image: UIImageView!
...
func configureView() {
if let detail = self.detailItem {
if let labelTitle = label {
labelTitle.text = detail["name"] as! String!
}
if let textData = text {
textData.text = detail["someData"] as! String!
}
// This obvious doesn't work
if let imageFile = image {
imageFile.image = detail["image"] as! UIImage!
}
}
}
So, my question is how can I get the Image from detail["image"]?
I assume that the image contained in detail["image"] is in your application Bundle (i.e.: not an image from an HTTP URL). So, you should use the init(named:) constructor from UIImage to load your image. Something like that:
if let myImage = UIImage(named: detail["image"]) {
myImageView.image = myImage
}
Edit:
Here is, also, your code with a better management of optionals and casts in configureView:
func configureView() {
if let detail = self.detailItem {
if let labelTitle = detail["name"] as? String {
myLabel.text = labelTitle
}
if let textViewContent = detail["someData"] as? String {
myTextView.text = textViewContent
}
if let myImageName = detail["image"] as? String {
if let myImage = UIImage(named: myImageName) {
myImageView.image = myImage
}
}
}
}

Retrieving image from firebase? (swift)

So i have a firebase structure like the pic below
Now i want to retrieve that image file that i've uploaded. to decode the base64String and show it. Every user can make a post and the information that will be sended to firebase has a description etc. and also have an image. now i tried to retrieve it whit this codes but nothing did work.
var REF_LIST = Firebase(url: "\(URL_BASE)/listItems")
REF_LIST.observeEventType(FEventType.Value, withBlock: { snapshot in
let image = snapshot.value.objectForKey("images") as! String
but this already gave me a nil error on that line, so i couldn't even decode. i think i understand why it's giving me a nil error, there is no images in listItems on firebase, you first have the unique ID and then the specs with images in. now i don't now how i can retrieve that information from that unique ID?
UPDATE:
the tableViewController what will receive the data from firebase:
import UIKit
import FBSDKLoginKit
import Alamofire
import Firebase
class ListVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
var lists = [List]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
dispatch_async(backgroundQueue, {
self.initObservers()
})
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.tableView.reloadData()
}
func initObservers() {
LoadingOverlay.shared.showOverlay(self.view)
DataService.ds.REF_LISTS.observeEventType(.Value, withBlock: { snapshot in
print(snapshot.value)
self.lists = []
if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {
for snap in snapshots {
print("SNAP: \(snap)")
if let listDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let list = List(listKey: key, dictionary: listDict)
self.lists.insert(list, atIndex:0)
}
}
}
self.tableView.reloadData()
LoadingOverlay.shared.hideOverlayView()
})
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lists.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCellWithIdentifier("ListCell") as? ListCell {
let list = self.lists[indexPath.row]
cell.request?.cancel()
cell.configureCell(list)
return cell
} else {
return ListCell()
}
}
}
the addController which post the data to firebase:
import UIKit
import Firebase
import Alamofire
import FBSDKCoreKit
class AddVC: UIViewController, UITextFieldDelegate, UITextViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
#IBOutlet weak var addTitle: UITextField!
#IBOutlet weak var addDescription: UITextView!
#IBOutlet weak var addLocation: UITextField!
#IBOutlet weak var placeholderLbl: UILabel!
#IBOutlet weak var freeSwitch: UISwitch!
#IBOutlet weak var tradeSwitch: UISwitch!
#IBOutlet weak var imageSelectorImg: UIImageView!
#IBOutlet weak var overlayView: UIView!
var currentUsername = ""
var imageSelected = false
var imagePicker: UIImagePickerController!
var base64String: NSString = ""
override func viewDidLoad() {
super.viewDidLoad()
addTitle.delegate = self
addDescription.delegate = self
addLocation.delegate = self
imagePicker = UIImagePickerController()
imagePicker.delegate = self
getCurrentUser()
hideKeyboardWhenTappedAround()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
addTitle.text = ""
addDescription.text = ""
addLocation.text = ""
freeSwitch.setOn(false, animated: false)
tradeSwitch.setOn(false, animated: false)
placeholderLbl.hidden = false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getCurrentUser() {
DataService.ds.REF_USER_CURRENT.observeEventType(FEventType.Value, withBlock: { snapshot in
let currentUser = snapshot.value.objectForKey("username") as! String
print("Username: \(currentUser)")
self.currentUsername = currentUser }, withCancelBlock: { error in
print(error.description)
})
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)
imageSelectorImg.image = image
dispatch_async(backgroundQueue, {
let uploadImage = image
let imageData = UIImageJPEGRepresentation(uploadImage, 0.5)
self.base64String = imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
})
imageSelected = true
}
#IBAction func selectImage(sender: UITapGestureRecognizer) {
presentViewController(imagePicker, animated: true, completion: nil)
}
func postToFirebase() {
// LoadingOverlay.shared.showOverlay(self.overlayView)
var post: Dictionary<String, AnyObject> = ["username": self.currentUsername, "description": self.addDescription.text!, "title": self.addTitle.text!, "location": self.addLocation.text!, "images": self.base64String]
if self.freeSwitch.on && self.tradeSwitch.on {
post["tradeOption"] = "Gratis/Te ruil"
} else if self.freeSwitch.on {
post["tradeOption"] = "Gratis"
} else if self.tradeSwitch.on {
post["tradeOption"] = "Te ruil"
}
let firebasePost = DataService.ds.REF_LISTS.childByAutoId()
firebasePost.setValue(post)
}
#IBAction func postListItem(sender: AnyObject) {
if let addTitle = addTitle.text where addTitle != "", let addDescription = addDescription.text where addDescription != "", let addLocation = addLocation.text where addLocation != "" {
dispatch_async(backgroundQueue, {
self.postToFirebase()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let listVC = storyboard.instantiateViewControllerWithIdentifier("TBC") as! UITabBarController
listVC.selectedIndex = 1
self.presentViewController(listVC, animated: false, completion: nil)
})
})
}
}
func textViewDidBeginEditing(textView: UITextView) {
placeholderLbl.hidden = true
}
func textViewDidEndEditing(textView: UITextView) {
if textView.text == "" {
placeholderLbl.hidden = false
}
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
and the swift file to configure the cell:
import UIKit
import Alamofire
import Firebase
class ListCell: UITableViewCell {
#IBOutlet weak var listImg: UIImageView!
#IBOutlet weak var listTitle: UILabel!
#IBOutlet weak var listTradeOption: UILabel!
#IBOutlet weak var listLocation: UILabel!
#IBOutlet weak var headImg: UIImageView!
var list: List!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
func retrieveImages() {
DataService.ds.REF_LISTS.observeEventType(FEventType.Value, withBlock: { snapshot in
if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {
for snap in snapshots {
let image = snap.value.objectForKey("images") as! String
let decodedData = NSData(base64EncodedString: image, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
let decodedImage = UIImage(data: decodedData!)
self.headImg.image = decodedImage
}
}
})
}
func configureCell(list: List) {
self.list = list
self.listTitle.text = list.listTitle
self.listTradeOption.text = list.listTradeOption
self.listLocation.text = list.listLocation
retrieveImages()
}
}
also the list Model file:
import Foundation
import Firebase
class List {
private var _listTitle: String!
private var _listDescription: String!
private var _listTradeOption: String!
private var _listLocation: String!
private var _listImageURL: String?
private var _listKey: String!
private var _listRef: Firebase!
var listTitle: String? {
return _listTitle
}
var listDescription: String? {
return _listDescription
}
var listTradeOption: String? {
return _listTradeOption
}
var listLocation: String? {
return _listLocation
}
var listKey: String {
return _listKey
}
var listImageURL: String? {
return _listImageURL
}
init(title: String, description: String, tradeOption: String, location: String, listImageURL: String?) {
self._listTitle = title
self._listDescription = description
self._listTradeOption = tradeOption
self._listLocation = location
self._listImageURL = listImageURL
}
init(listKey: String, dictionary: Dictionary<String, AnyObject>) {
self._listKey = listKey
if let title = dictionary ["title"] as? String {
self._listTitle = title
}
if let desc = dictionary ["description"] as? String {
self._listDescription = desc
}
if let trade = dictionary ["tradeOption"] as? String {
self._listTradeOption = trade
}
if let loc = dictionary ["location"] as? String {
self._listLocation = loc
}
if let imgUrl = dictionary["images"] as? String {
self._listImageURL = imgUrl
}
self._listRef = DataService.ds.REF_LISTS.childByAppendingPath(self._listKey)
}
}
i've got also a DataServicefile, where i create a user by unique ID with this code:
var REF_USER_CURRENT: Firebase {
let uid = NSUserDefaults.standardUserDefaults().valueForKey(KEY_UID) as! String
let user = Firebase(url: "\(REF_BASE)").childByAppendingPath("users").childByAppendingPath(uid)
return user!
}
func createFirebaseUser(uid: String, user: Dictionary<String, String>) {
REF_USERS.childByAppendingPath(uid).setValue(user)
}
i know it's a lot but maybe the best way to help :)
Try editing this in List Cell
var imageURL = String()
func retrieveImages() {
let decodedData = NSData(base64EncodedString: imageURL, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
let decodedImage = UIImage(data: decodedData!)
self.headImg.image = decodedImage
}
func configureCell(list: List) {
self.list = list
self.listTitle.text = list.listTitle
self.listTradeOption.text = list.listTradeOption
self.listLocation.text = list.listLocation
self.imageURL = list.listImageURL //you already had the image url for that specific cell
retrieveImages()
}
Storing and accessing images using base64String in firebase is not an
efficient way, instead of that we can use FirebaseStorage (Google cloud storage
bucket) for uploading images to Firebase and it will provide us
download URL for a particular image. We can store that URL into our database simply in a string format and access it whenever we
required and then download the corresponding image from that URL by
using SDWebImage.
Refer below link for integrating FirebaseStorage into your project: https://firebase.google.com/docs/storage/ios/upload-files

How can I reload immediately my UITableViewCell in Swift?

class DropTvViewController: UIViewController , UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
var dataTransfer = DataTransfer()
var responseString : String = ""
let storeData = StoreData()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
let pfod = PostForData()
pfod.forData
{ jsonString in
self.responseString = jsonString as String
var dict = self.dataTransfer.jsonToArray(self.responseString)!
if let x: AnyObject = dict.valueForKey("readlist")
{
println( dict.count )
println("X + \(x)")
for var i = 0 ; i < dict.count-1 ; i+=2
{
println("i : \(i)")
let y: AnyObject = x.objectAtIndex(i)
let z: AnyObject? = y.objectForKey("epipic")
let title : AnyObject? = y.objectForKey("epititle")
let time : AnyObject? = y.objectForKey("droptagcreatetime")
let pg : AnyObject? = y.objectForKey("pgname")
var imagessss = UIImage (data : pfod.forPicture())
self.storeData.add(title as! String, aFs: pg as! String, aTs: time as! String, ph: imagessss! , field1s: z as! String, field2s: z as! String, field3s: z as! String, field4s: z as! String )
// I do reload in here,but it will delay about ten seconds.
// I am sure the data is ready to read
self.tableView.reloadData()
}
}
}
}
You can use self.tableView.reloadData() which you are doing, but just in the wrong part of the loop. Just move it outside and you should be fine :)
If you're looking to reload a specific table cell then try: self.tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.None)
Answer taken from here: https://stackoverflow.com/a/26709571/4891259