現在、ラベルコンテンツをテーブルビューコントローラにロードする必要のあるアプリケーションで作業しています。私は、テーブルビューに値を設定したい文字列値の配列を作成しましたが、何らかの理由でコンテンツがシミュレータに表示されません。私はエラーは発生していませんが、データが登録されていないようです。どのように私はこれを解決することができますか?私はまた、適切にデータソースとデリゲートへの出口接続を作成していると信じてテーブルビューを作成しようとしましたが、ラベルコンテンツがシミュレータに表示されません
categoryTableViewController.swift
// Style Guide
//
// Created by Claudia Laurie on 5/30/16.
// Copyright © 2016 Claudia Laurie. All rights reserved.
//
import UIKit
//struct Color {
// let red, green, blue: Double
// init(red: Double, green: Double, blue: Double) {
// self.red = red
// self.green = green
// self.blue = blue
// }
// init(white: Double) {
// red = white
// green = white
// blue = white
// }
//}
I
class clothing_category: NSObject {
let name: String!
init (name: String) {
self.name = name
}
}
class categoryTableViewController: UITableViewController {
// MARK: Properties
// Create an array to hold the clothing.
var clothing_categories = [clothing_category]()
override func viewDidLoad() {
super.viewDidLoad()
// Register cells? let me google...is this why nothing was showing up in the cells themselves despite loading the data? maybe
self.tableView.registerClass(catgeoriesTableViewCell.self, forCellReuseIdentifier: "categoriesTableViewCell")
// Load sample data
loadSampleClothing_categories()
}
func loadSampleClothing_categories() {
clothing_categories.append(clothing_category(name:"Jackets"))
clothing_categories.append(clothing_category(name: "Accessories"))
clothing_categories.append(clothing_category(name: "Pants"))
clothing_categories.append(clothing_category(name: "Color"))
clothing_categories.append(clothing_category(name: "Tops"))
clothing_categories.append(clothing_category(name: "Dressing for an Occaision"))
// Load up the array when the view is loaded.
clothing_categories.append(clothing_category(name:"Jackets"))
clothing_categories.append(clothing_category(name: "Accessories"))
clothing_categories.append(clothing_category(name: "Pants"))
clothing_categories.append(clothing_category(name: "Color"))
clothing_categories.append(clothing_category(name: "Tops"))
clothing_categories.append(clothing_category(name: "Dressing for an Occaision"))
// 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.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return clothing_categories.count
}
// Table view cells are reused and should be dequeued using a cell identifier.
let cellIdentifier = "categoriesTableViewCell"
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// This is the line that is failing, lets find out why
let cell = tableView.dequeueReusableCellWithIdentifier("categoriesTableViewCell", forIndexPath: indexPath) as! catgeoriesTableViewCell
//Fetches the appropriate clothing_catgeory for the data source layout.
let category = clothing_categories[indexPath.row]
cell.nameclothing_category.text = category.name
return cell
}
:
は、以下の私のテーブルビューコントローラファイルです。
なぜあなたのデータがInterface Builderに表示されると思いますか?実行中のアプリにのみ表示されます。 – rmaddy
また、アプリシミュレータには表示されません:/ –
デバッガでは、使用時に表示される内容は何ですか?正しいメソッドが呼び出されていますか? 'tableView:numberOfRowsInSection:'と 'tableView:cellForRowAtIndexPath:'に正しい値が返されていますか?あなたの 'cellIdentifier'がIBとあなたのコードの両方で正しいことを確認しましたか?基本的にどのような問題があなたのデバッグで除外されていますか? –