我正在开发一个小应用程序,我需要从字典数组中获取数据。在其中创建动态部分和行。在访问数组时,我收到了预期模式的错误。请帮忙解决这个问题。我过去两天就遇到了这个问题。
我在网上收到错误: 让[workCategory:[(portName,portDesc)]] = portfolioData [indexPath.row]! 我已经三次使用这条线了,我加时错误了。
// ViewController.swift
// tableDemo
//
// Created by User 1 on 03/10/15.
// Copyright © 2015 User 1. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
let portfolioData = [
"Websites" :
[("CDO Group","This portal helps in real estate business"),("Food Truck","This website helps you to find food and Book."),("The Grand Residency","This portal helps you to find your home.")],
"Applications" : [("The Judefly","This application helps you to select travelling destination."),("The Kindle Ebook","An online eBook Store."),("Nanolux","The technology to next generation.")],
"Softwares" : [("QPM Agility","This software helps to manage whole organization."),("Nikhil","A softwre to next gen")]]
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
var count = 0
for variable in portfolioData
{
print(variable)
count++
}
return count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section
{
case 0 :
return portfolioData["Websites"]!.count
case 1 :
return portfolioData["Applications"]!.count
default:
return portfolioData["Softwares"]!.count
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
var count = 0
if indexPath.section == 0
{
let [workCategory:[(portName,portDesc)]] = portfolioData[indexPath.row]!
cell.textLabel!.text = portName
cell.detailTextLabel?.text = portDesc
let variable = "img" + String(count)
let myImage = UIImage(named: variable)
cell.imageView?.image = myImage
count++
}
else if indexPath.section == 1
{
let [workCategory:[(portName,portDesc)]] = portfolioData[indexPath.row]
cell.textLabel!.text = portName
cell.detailTextLabel?.text = portDesc
let variable = "img" + String(count)
let myImage = UIImage(named: variable)
cell.imageView?.image = myImage
count++
}
else
{
let [workCategory:[(portName,portDesc)]] = portfolioData[indexPath.row]
cell.textLabel!.text = portName
cell.detailTextLabel?.text = portName
let variable = "img" + String(count)
let myImage = UIImage(named: variable)
cell.imageView?.image = myImage
count++
}
//count = 0
return cell
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0
{
return "Websites"
}
else if section == 1
{
return "Applications"
}
else
{
return "Softwares"
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}