Comment afficher l'étiquette lors de l'affichage de tableau est vide
Je suis à essayer de comprendre comment afficher un message à l'intérieur d'une vue de la table, quand la table est vide. Je tiens à dire quelque chose comme: "Vous n'avez pas ajouté de transactions encore. Appuyez sur le bouton ajouter pour obtenir commencé.". Évidemment, j'aurais besoin de revenir à ce message si l'utilisateur supprime toutes les cellules, trop.
C'est le code que j'ai actuellement dans ma table view controller:
class ThirdViewController: UITableViewController {
override func viewWillAppear(animated: Bool) {
self.tableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
//Uncomment the following line to preserve selection between presentations
//self.clearsSelectionOnViewWillAppear = false
//Uncomment the following line to display an Edit button in the navigation bar for this view controller.
//self.navigationItem.rightBarButtonItem = self.editButtonItem
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
//Dispose of any resources that can be recreated.
}
//#pragma mark - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
//#warning Potentially incomplete method implementation.
//Return the number of sections.
return 1
}
override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
//#warning Incomplete method implementation.
//Return the number of rows in the section.
return arrayObject.paymentsArray().count
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:CustomTransactionTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomTransactionTableViewCell
cell.paymentNameLabel.text = (arrayObject.paymentsArray().objectAtIndex(indexPath.row)) as String
cell.costLabel.text = (arrayObject.costArray().objectAtIndex(indexPath.row)) as String
cell.dateLabel.text = (arrayObject.dateArray().objectAtIndex(indexPath.row)) as String
if arrayObject.imageArray().objectAtIndex(indexPath.row) as NSObject == 0 {
cell.paymentArrowImage.hidden = false
cell.creditArrowImage.hidden = true
} else if arrayObject.imageArray().objectAtIndex(indexPath.row) as NSObject == 1 {
cell.creditArrowImage.hidden = false
cell.paymentArrowImage.hidden = true
}
return cell
}
override func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
return true
}
override func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
if let tv=tableView {
arrayDataCost.removeObjectAtIndex(indexPath!.row)
arrayDataImage.removeObjectAtIndex(indexPath!.row)
arrayDataPayments.removeObjectAtIndex(indexPath!.row)
arrayDataDate.removeObjectAtIndex(indexPath!.row)
tv.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
}
}
Toute aide serait grandement appréciée!
OriginalL'auteur user3746428 | 2014-07-24
Vous devez vous connecter pour publier un commentaire.
Vous pouvez définir le backgroundView à un UILabel (Ou un certain point de vue, vous faites lorsque la table est vide
quelque chose comme cela fonctionne très bien pour moi
Savez-vous pourquoi il montre étiquette, même si le comte n'est pas à 0?
Vous devriez faire tableView.backgroundView = nil dans le else
OriginalL'auteur Putt Potsawee
OriginalL'auteur Sanjay Mali
Remplacer votre
viewDidLoad()
méthode comme ceci:J'ai mis à jour ma réponse. auto.vue.addSubview(de soi.yourLabel); méthode permet d'ajouter des étiquettes à yourSomeViewController
Avez-vous essayé de mettre l'étiquette sous la tableView de sorte qu'il devient visible que lorsque le tableView devient cachée?
OriginalL'auteur Shamsiddin
Vous pouvez utiliser cette méthode. Pas de fonction de limite de
Swift3
OriginalL'auteur J.Arji
Vous pouvez masquer la tableView et afficher l'étiquette, ou d'afficher une sorte d'animation qui réduit l'alpha de l'une des vues pour un "fade" effet.
OriginalL'auteur user3871275