면책 조항 : 코딩 세계는 처음이지만 코드 작성의 새로운 것은 없습니다.테이블 뷰 행에 plist의 데이터 채우기
섹션 헤더로 장치 가져 오기. 하지만 회사를 tableView 내부의 행으로 사용할 수는 없습니다. 어떻게
let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath)
같은 회사 이름이 장치 유형
import UIKit
class MainPageViewController: UITableViewController {
var devices = [AnyObject]()
let CellIdentifier = "Cell Identifier"
var companyName: [AnyObject] {
if let companyName = devices["Comp"] as? [AnyObject] {
return companyName
} else {
return [AnyObject]()
}
}
override func viewDidLoad() {
super.viewDidLoad()
title = "Devices"
let filePath = Bundle.main.path(forResource: "Array", ofType: "plist")
if let path = filePath {
devices = NSArray(contentsOfFile: path) as! [AnyObject]
}
print(device)
tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: CellIdentifier)
}
override func numberOfSections(in tableView: UITableView) -> Int {
return devices.count
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
var titleName = title
if let deviceHeader = devices[section] as? [String: AnyObject], let titled = deviceHeader["Device"] as? String
{
titleName = titled
}
return titleName
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return companyName.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath)
if let company = companyName[indexPath.row] as? [String: AnyObject], let name = company["Company"] as? String {
cell.textLabel?.text = name
}
return cell;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
에
<array>
<dict>
<key>Device</key>
<string>Smartphones</string>
<key>Comp</key>
<array>
<dict>
<key>Company</key>
<string>Apple</string>
</dict>
<dict>
<key>Company</key>
<string>Samsung</string>
</dict>
</array>
</dict>
<dict>
<key>Device</key>
<string>Notebooks</string>
<key>Comp</key>
<array>
<dict>
<key>Company</key>
<string>HP</string>
</dict>
<dict>
<key>Company</key>
<string>Dell</string>
</dict>
<dict>
<key>Company</key>
<string>Lenovo</string>
</dict>
</array>
</dict>
</array>
</plist>
재정의 FUNC의있는 tableView (INT _있는 tableView : : : jQuery과, numberOfRowsInSection 절) 여기
–@HimanshuMoradiya가 companyName.count를 추가했지만 아직 데이터를 가져올 수 없습니다. – Dar
실제 코드를 복사하여 붙여 넣으십시오. – rmaddy