popToRootViewControllerAnimated is not updating UITableView - uitableview

I'm working on small CoreData program with one UITableView with embedded Navigation controller and UIViewController, where to add the CoreData.
The problem is that I can't figure out how to reload the data in the table after press the save button.
I have tried to use popToRootViewControllerAnimated(true) in the #IBAction func buttonSavePressed(sender: UIBarButtonItem), but this just send me to the TableView without reloading the data.
#IBAction func buttonSavePressed(sender: UIBarButtonItem) {
self.navigationController?.popToRootViewControllerAnimated(true)
}
I have also tried self.navigationController?.showViewController(contractsView, sender: storyboard) but this create another view in the stack, not the original, if I can explained like this.
#IBAction func buttonSavePressed(sender: UIBarButtonItem) {
let contractsView = self.storyboard?.instantiateViewControllerWithIdentifier("ContractsTableViewControllerStoryboardID") as ContractsTableViewController
self.navigationController?.showViewController(contractsView, sender: storyboard)
}
I am new with the programming, which means that I can not aways ask the right questions. So I am posting the code, which is in working stage without comments - sorry
// ContractsTableViewController.swift
import UIKit
import CoreData
class ContractsTableViewController: UITableViewController {
//, UITableViewDelegate, UITableViewDataSource
var totalContracts = 0
#IBOutlet var tableContracts: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
var appDel = (UIApplication.sharedApplication().delegate as AppDelegate)
var context = appDel.managedObjectContext!
var request = NSFetchRequest(entityName: "Contract")
request.returnsObjectsAsFaults = false
totalContracts = context.countForFetchRequest(request, error: nil)
println(totalContracts)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return totalContracts
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Default")
var appDel = (UIApplication.sharedApplication().delegate as AppDelegate)
var context = appDel.managedObjectContext!
var request = NSFetchRequest(entityName: "Contract")
request.returnsObjectsAsFaults = false
var results: NSArray = context.executeFetchRequest(request, error: nil)!
var thisContract = results[indexPath.row] as Contract
cell.detailTextLabel!.text = "From" + " " + thisContract.stratdate + " " + "to" + " " + thisContract.enddate
cell.textLabel!.text = thisContract.workingdays + " " + "days" + " " + "as" + " " + thisContract.position + " " + "on" + " " + thisContract.ship
return cell
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Default")
var appDel = (UIApplication.sharedApplication().delegate as AppDelegate)
var context = appDel.managedObjectContext!
var request = NSFetchRequest(entityName: "Contract")
request.returnsObjectsAsFaults = false
var results: NSArray = context.executeFetchRequest(request, error: nil)!
context.deleteObject(results[indexPath.row] as NSManagedObject)
context.save(nil)
totalContracts = totalContracts - 1
tableContracts.reloadData()
}
}

When your tableView controller loads back viewDidAppear function will called. so you can reload tableView into that function like this:
override func viewDidAppear(animated: Bool) {
tableView.reloadData()
}
You can navigate to RootView this way:
self.navigationController?.popToRootViewControllerAnimated(true)
This is working fine.
HERE is your working project.

First of all, take the IBOutlet of UITableView in ContractsViewController. Then put the reload the tableview using the below code:
self.myTableView.reloadData()

Related

TableView definition conflict with previous using CoreData in Mutable array

I am trying to access the CoreData and putting it into the TableView so i have the data into the Mutable array but when i try to access it into the TableView then i got this error.
My code is as follows:
import UIKit
import CoreData
class TableView: UIViewController, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
var desc_arr: [String] = []
var amt_arr: [String] = []
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext
let request = NSFetchRequest(entityName: "Expense")
request.returnsObjectsAsFaults = false
do {
let results = try context.executeFetchRequest(request)
if results.count > 0 {
for result in results as! [NSManagedObject] {
if let desc = result.valueForKey("desc") as? String {
print(desc)
desc_arr.append(desc)
}
if let amt = result.valueForKey("amt") as? String{
print(amt)
amt_arr.append(amt)
}
}
}
} catch {
print("Fetch Failed")
}
print(desc_arr)
print(amt_arr)
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return desc_arr.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.textLabel?.text = desc_arr[indexPath.row]
return cell
}
}
}

Passing coredata from tableview to another tableview

I am struggling with getting my care data to populate my second tableview controller. The data is populating the first tableview and I can select a row and the segue is used to go to the second table but the labels are not populated.
I've looked all over and have found older samples or obj-c but I cannot figure it out, so any help pointing this n00b in the right direction will be helpful.
Here is what I have, I think I am missing how to populate a variable to pass in prepareForSegue in the list tableview, but I could be wrong. I get a warning error in that function (Warning cannot assign value of type 'ListEntity' to type '[ListEntity]').
CoreData
Entity = ListEntity
Attributes = title, event & location (all as Strings)
listTableViewController
import UIKit
import CoreData
class ListTableViewController: UITableViewController {
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
var lists = [ListEntity]()
override func viewDidLoad() {
super.viewDidLoad()
self.title = "The List"
let addButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: #selector(ListTableViewController.addButtonMethod))
navigationItem.rightBarButtonItem = addButton
}
func addButtonMethod() {
print("Perform action")
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
reloadData()
tableView.reloadData()
}
func reloadData() {
let fetchRequest = NSFetchRequest(entityName: "ListEntity")
do {
if let results = try managedObjectContext.executeFetchRequest(fetchRequest) as? [ListEntity] {
lists = results
}
} catch {
fatalError("There was an error fetching the list!")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lists.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ListCell") as! ListTableViewCell
let list = lists[indexPath.row]
cell.configurationWithSetup(list)
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("DetailsSegue", sender: self)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "DetailsSegue" {
let destinationVC = segue.destinationViewController as! DetailsTableViewController
let indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!
print(indexPath.row) // Print the Row selected to console
// Place the code to pass data here?
// destinationVC.lists = lists[indexPath.row]
// Warning cannot assign value of type 'ListEntity' to type '[ListEntity]'
}
}
}
listTableViewCell
import UIKit
class ListTableViewCell: UITableViewCell {
#IBOutlet weak var titleLabel: UILabel!
func configurationWithSetup(list: AnyObject) {
titleLabel.text = list.valueForKey("title") as! String?
}
}
detailsTableViewController
import UIKit
import CoreData
class DetailsTableViewController: UITableViewController {
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
var lists = [ListEntity]()
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Table view data source
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("DataCell") as! DetailsTableViewCell
let list = lists[indexPath.row]
cell.configurationWithSetup(list)
return cell
}
}
detailsTableViewCell
import UIKit
import CoreData
class DetailsTableViewCell: UITableViewCell {
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet weak var eventLabel: UILabel!
#IBOutlet weak var locationLabel: UILabel!
func configurationWithSetup(list: AnyObject) {
titleLabel.text = list.valueForKey("title") as! String?
eventLabel.text = list.valueForKey("event") as! String?
locationLabel.text = list.valueForKey("location") as! String?
}
}
The warning contains the answer - just change
var lists = [ListEntity]() to
var lists = ListEntity(), or var lists:ListEntity! and when you prepare for segue set that value.
Then you will need to change
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("DataCell") as! DetailsTableViewCell
// as data source is not array you can just you the item you passed
// let list = lists[indexPath.row]
cell.configurationWithSetup(lists)
return cell
}
You should use a static table view if you just want one cell
More info per you current issue
class DetailsTableViewController: UITableViewController {
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
var theDetailListEntity:ListEntity!
override func viewDidLoad() {
super.viewDidLoad()
print(theDetailListEntity) // check that you passed it across
}
// MARK: - Table view data source
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("DataCell") as! DetailsTableViewCell
cell.configurationWithSetup(theDetailListEntity)
return cell
}
}
Don't forget to add prepare for segue in the listTableViewController otherwise theDetailListEntity won't be set... and then it will crash.
Depending on how you set up your segue, it may differ. But this is what you need
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("showMyDetailView", sender: indexPath)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showMyDetailView" {
guard let
vc = segue.destinationViewController as? DetailsTableViewController,
ip = sender as? NSIndexPath else { fatalError() }
let item = lists[ip.row]
vc.theDetailListEntity = item
// set the item in the next VC
tableView.deselectRowAtIndexPath(ip, animated: true)
}
}

UITableview not refreshing on viewWillAppear or performSelectorOnMainThread with 1 row

So, I am trying to do something that I think is fairly simple, yet this is causing me no end of pain.
Essentially I have a ViewController, and from here you can open another ViewController which again you can load another ViewController from. In this last ViewController you can select a row which will add some data to NSUserdefaults (Using a class that I built to handle this data)
This all works fine, and the data is added. Now when I go back to my first ViewController whence the journey began, using viewWillAppear I ask it to get the data from NSUserdefaults and then refresh the data in a table that is in this view.
let jsonData = JSON(NSUserDefaults.standardUserDefaults().objectForKey("set")!)
self.tracks = jsonData.arrayObject!
print(self.tracks)
self.tblSongs.reloadData()
Now this never seems to work when there is just 1 row in the array, however if there is more than 1 row, then everything works fine and the table is visible with the required amount of data.
The Print does indeed show the data that is stored, and I can see the single row that is stored but is not showing up in the table.
Has anyone had anything similar or any idea what I can do to solve this?
I have tried using a delegate, NSNotificationCenter, and performing spells but everything returns the same result.
Many thanks in advance for your help
*Disclaimer I am new to native iOS and Swift being a JS Developer and previously using Titanium
EDIT: I have logged numberOfRowsInSection and this returns 1 as expected, but cellForRowAtIndexPath does not get fired
EDIT 2: Here is the cellForRowAtIndexPath code, this isn't fired even though there is 1 item in the array and numberOfRowsInSection says 1. This does work fine if you re-launch the app
EDIT 3: Here is the entire Class
import Foundation
import UIKit
class Main: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet weak var viewNoTracks: UIView!
#IBOutlet weak var viewTracksNoSet: UIView!
#IBOutlet weak var btnPlay: UIButton!
#IBOutlet weak var tblSongs: UITableView!
#IBOutlet weak var lblStatus: UILabel!
#IBOutlet weak var btnSubmitSet: UIButton!
var tracks = []
let setMgr = SetManager()
override func viewDidLoad() {
super.viewDidLoad()
let bgColor: UIColor = UIColor.whiteColor()
self.btnSubmitSet.layer.borderColor = bgColor.CGColor
self.btnSubmitSet.layer.borderWidth = 1
self.tblSongs.delegate = self
self.tblSongs.dataSource = self
if self.setMgr.getCurrentSetCount() > 0 {
self.viewTracksNoSet.hidden = false
self.viewNoTracks.hidden = true
self.updateData()
} else {
self.viewTracksNoSet.hidden = true
self.viewNoTracks.hidden = false
}
self.checkSetStatus()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
dispatch_async(dispatch_get_main_queue()) {
if self.setMgr.getCurrentSetCount() > 0 {
self.viewTracksNoSet.hidden = false
self.viewNoTracks.hidden = true
self.updateData()
} else {
self.viewTracksNoSet.hidden = true
self.viewNoTracks.hidden = false
}
self.checkSetStatus()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func openPlay(sender: AnyObject){
self.performSegueWithIdentifier("segueChoonSelector", sender: nil)
}
#IBAction func unwindToMain(segue: UIStoryboardSegue){
}
#IBAction func submitSet(sender: AnyObject){
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellMainSong", forIndexPath: indexPath) as! CellMainSong
let row = self.tracks[indexPath.row]
var artist = row["artist"] as! String
artist = artist.stringByReplacingOccurrencesOfString("&", withString: "&", options: NSStringCompareOptions.LiteralSearch, range: nil)
var song = row["song"] as! String
song = song.stringByReplacingOccurrencesOfString("&", withString: "&", options: NSStringCompareOptions.LiteralSearch, range: nil)
var genre = row["genre"] as! String
genre = genre.stringByReplacingOccurrencesOfString("&", withString: "&", options: NSStringCompareOptions.LiteralSearch, range: nil)
print(artist)
cell.lblDetails.text = artist + " - " + song + " - " + genre
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tracks.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete {
let row = self.tracks[indexPath.row]
let tid = row["tid"] as! String
self.setMgr.removeFromSet(tid)
self.updateData()
}
}
func UITableView_Auto_Height()
{
if(self.tblSongs.contentSize.height < self.tblSongs.frame.height){
var frame: CGRect = self.tblSongs.frame;
frame.size.height = self.tblSongs.contentSize.height;
self.tblSongs.frame = frame;
}
}
func setSetLabelOrButton(){
if self.setMgr.getCurrentSetCount() < 3 {
let currCountInt: Int = self.setMgr.getCurrentSetCount()
let tracksLeft = 3 - currCountInt
let currentCount = String(tracksLeft)
self.btnSubmitSet.hidden = true
self.lblStatus.hidden = false
if currentCount == "1" {
self.viewTracksNoSet.hidden = false
self.viewNoTracks.hidden = true
self.lblStatus.text = "Hey DJ, you are " + currentCount + " track away from rocking the dancefloor"
} else if currentCount == "3" {
self.viewTracksNoSet.hidden = true
self.viewNoTracks.hidden = false
} else {
self.lblStatus.text = "Hey DJ, you are " + currentCount + " tracks away from rocking the dancefloor"
}
} else if self.setMgr.getCurrentSetCount() == 3 {
self.lblStatus.hidden = true
self.btnSubmitSet.hidden = false
}
}
func updateData(){
let jsonData = JSON(NSUserDefaults.standardUserDefaults().objectForKey("set")!)
self.tracks = jsonData.arrayObject!
print(self.tracks)
self.tblSongs.reloadData()
self.performSelectorOnMainThread(Selector("updateTableData"), withObject: self.tblSongs, waitUntilDone: false)
self.setSetLabelOrButton()
self.UITableView_Auto_Height()
}
func updateTableData(){
self.tblSongs.reloadData()
}
func checkSetStatus(){
let setStatus = SetStatus()
setStatus.getSetStatus { (resp) -> Void in
//print(resp)
}
}
}
Didn't get the reason Bt just log what value does "numberOfSections" in tableview returns. It may not be the reason but just try
I found out the issue. Turns out that self.UITableView_Auto_Height() was being called before the data had been loaded, causing the table to render at 0 height. Although interestingly it still wasn't firing the cellForRowAtIndex, so perhaps an issue with the lifecycle in this case

UITableViewController: NSInternalInconsistencyException

After searching for solution I cant resolve this issue,
I have this code to list the data from core data:
import UIKit
import CoreData
class ViewControllerClass: UITableViewController, NSFetchedResultsControllerDelegate{
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
var fetchedResultController: NSFetchedResultsController = NSFetchedResultsController()
var intermedioLat:String = ""
var intermedioLong:String = ""
#IBOutlet weak var listagem: UITableView!
var velocidade = ["40","50","70","90","100","120"]
func textFieldSouldReturn (textField: UITextField) -> Bool{
textField.resignFirstResponder()
return true
}
override func viewDidLoad() {
print(intermedioLat)
print(intermedioLong)
fetchedResultController = getFetchedResultController()
fetchedResultController.delegate = self
fetchedResultController.performFetch(nil)
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func getFetchedResultController() -> NSFetchedResultsController {
fetchedResultController = NSFetchedResultsController(fetchRequest: taskFetchRequest(), managedObjectContext: managedObjectContext!, sectionNameKeyPath: nil, cacheName: nil)
return fetchedResultController
}
func taskFetchRequest() -> NSFetchRequest {
let fetchRequest = NSFetchRequest(entityName: "Radar")
let sortDescriptor = NSSortDescriptor(key: "descricao", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
return fetchRequest
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
let numberOfSections = fetchedResultController.sections?.count
return numberOfSections!
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let numberOfRowsInSection = fetchedResultController.sections?[section].numberOfObjects
return numberOfRowsInSection!
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Celula", forIndexPath: indexPath) as! UITableViewCell
let task = fetchedResultController.objectAtIndexPath(indexPath) as! Radar
cell.textLabel?.text = task.descricao
return cell
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
let managedObject:NSManagedObject = fetchedResultController.objectAtIndexPath(indexPath) as! NSManagedObject
managedObjectContext?.deleteObject(managedObject)
managedObjectContext?.save(nil)
}
func controllerDidChangeContent(controller: NSFetchedResultsController) {
tableView.reloadData()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "fromEventTableToAddEvent"{
var enviaInterLat : adicionarRadar = segue.destinationViewController as! adicionarRadar
enviaInterLat.latitude = intermedioLat
var enviaInterLong : adicionarRadar = segue.destinationViewController as! adicionarRadar
enviaInterLong.longitude = intermedioLong
}}
}
and I have a error like this:
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[UITableViewController
loadView] loaded the "TuG-ju-H3E-view-l3X-mv-HmR" nib but didn't get a
UITableView.'
*** First throw call stack: libc++abi.dylib: terminating with uncaught exception of type NSException
I dont know what more to do because I try everything
You declare your class as a UITableViewController in this case the view outlet must be connected to the table view. However if you want a view that contains a UITableView then simple make the controller a UIViewController which conforms to the UITableViewDelegate and UITableViewDataSource protocols and this will go away.
Change it to
class ViewControllerClass: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate

Table View doesn't show data from JSON

My Code:
import UIKit
class HomeVCHome: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet weak var usernameLabel: UILabel!
#IBOutlet weak var tableView: UITableView!
var names: [String] = []
var contacts: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self;
self.tableView.dataSource = self;
let url=NSURL(string:"http://mysite/json.aspx")!
let allContactsData=NSData(contentsOfURL:url)
var allContacts: AnyObject! = NSJSONSerialization.JSONObjectWithData(allContactsData!, options: NSJSONReadingOptions(0), error: nil)
if let json = allContacts as? Array<AnyObject> {
print(json)
for index in 0...json.count-1 {
let contact : AnyObject? = json[index]
print(contact)
let collection = contact! as Dictionary<String, AnyObject>
print(collection)
print(collection["name"])
let name : AnyObject? = collection["name"]
let cont : AnyObject? = collection["cont"]
names.append(name as String)
contacts.append(cont as String)
}
}
println(names)
println(contacts)
tableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return self.names.count;
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected name : "+names[indexPath.row])
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
var cell = tableView.dequeueReusableCellWithIdentifier("cell") as? UITableViewCell
println("ok 1")
if !(cell != nil) {
cell = UITableViewCell(style: .Subtitle, reuseIdentifier: "cell")
}
println("ok 2")
cell?.textLabel.text=self.names[indexPath.row]
cell?.detailTextLabel?.text = self.contacts[indexPath.row]
println("ok 3")
return cell!
}
}
i try to run, and i can't see my data in tableView... just blank in table View
and i try another code but the same result (table view blank)...
what should i do? i don't know its my mistake code or my simulator have problems like that...
pls change the method and try:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) as UITableViewCell
cell.textLabel.text=self.names[indexPath.row]
cell.detailTextLabel?.text = self.contacts[indexPath.row]
return cell
}

Resources