-1
현재 레이블 내용을 표보기 컨트롤러로로드해야하는 앱에서 작업하고 있습니다. 테이블 뷰를 채울 문자열 값 배열을 만들었지 만 어떤 이유로 인해 콘텐츠가 시뮬레이터에 표시되지 않습니다. 오류는 발생하지 않지만 데이터가 등록되지 않은 것으로 보입니다. 내가 어떻게 해결할 수 있을지에 대한 생각? 나는 또한 제대로 데이터 소스 및 대리자 출구 연결을 만든 생각표보기를 채우려 고 시도했지만 레이블 내용이 시뮬레이터에 나타나지 않습니다.
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 :'에 반환 되는가? IB와 코드 모두에서 'cellIdentifier'가 올바른지 확인 했습니까? 기본적으로 디버깅에서 어떤 문제를 배제 했습니까? –