我正在尝试将从 api 请求中获得的结果转换成一个表:
请求结果:
[(
"LEC 001",
"10:00",
"11:20",
PHY,
150,
"Tompkins,Dave"
), (
"LEC 002",
"10:00",
"11:20",
PHY,
235,
"Holtby,Daniel James"
), (
"LEC 003",
"11:30",
"12:50",
MC,
4045,
"Akinyemi,John Akinlabi"
), (
"LEC 004",
"11:30",
"12:50",
MC,
2038,
"Roegiest,Adam Micheal"
), (
"LEC 005",
"13:00",
"14:20",
RCH,
307,
"Tompkins,Dave"
), (
"LEC 006",
"13:00",
"14:20",
DWE,
3522,
"Istead,Lesley Ann"
), (
"LEC 007",
"14:30",
"15:50",
DWE,
3522,
"Istead,Lesley Ann"
), (
"LEC 008",
"14:30",
"15:50",
MC,
1056,
"Holtby,Daniel James"
), (
"LEC 009",
"16:00",
"17:20",
MC,
2034,
"Akinyemi,John Akinlabi"
), (
"LEC 010",
"16:00",
"17:20",
MC,
2035,
"Roegiest,Adam Micheal"
), (
"LEC 011",
"08:30",
"09:50",
MC,
4020,
"Heinle,Albert"
)]
这是我想象中的表格的样子
最佳答案
1) First i parsed your data it was in tuple
如果你想了解更多如何从元组中获取值,你可以引用这篇文章 http://www.codingexplorer.com/tuples-in-swift-create-read-and-return/
这是输出
2) i implemented in the table view
//
// ViewController.swift
// test tableview
//
// Created by O-mkar on 30/12/15.
// Copyright © 2015 test. All rights reserved.
//
import UIKit
class ViewController: UITableViewController {
let testArray = [(
"LEC 001",
"10:00",
"11:20",
"PHY,150",
"Tompkins,Dave"
), (
"LEC 002",
"10:00",
"11:20",
"PHY,235",
"Holtby,Daniel James"
), (
"LEC 003",
"11:30",
"12:50",
"MC,4045",
"Akinyemi,John Akinlabi"
), (
"LEC 004",
"11:30",
"12:50",
"MC,2038",
"Roegiest,Adam Micheal"
), (
"LEC 005",
"13:00",
"14:20",
"RCH,307",
"Tompkins,Dave"
), (
"LEC 006",
"13:00",
"14:20",
"DWE,3522",
"Istead,Lesley Ann"
), (
"LEC 007",
"14:30",
"15:50",
"DWE,3522",
"Istead,Lesley Ann"
), (
"LEC 008",
"14:30",
"15:50",
"MC,1056",
"Holtby,Daniel James"
), (
"LEC 009",
"16:00",
"17:20",
"MC,2034",
"Akinyemi,John Akinlabi"
), (
"LEC 010",
"16:00",
"17:20",
"MC,2035",
"Roegiest,Adam Micheal"
), (
"LEC 011",
"08:30",
"09:50",
"MC,4020",
"Heinle,Albert"
)]
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return testArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let myCell:UITableViewCell=tableView.dequeueReusableCellWithIdentifier("prototype", forIndexPath: indexPath)
myCell.textLabel?.text = "\(testArray[indexPath.row].0) | \(testArray[indexPath.row].1) | \(testArray[indexPath.row].2) | \(testArray[indexPath.row].3) | \(testArray[indexPath.row].4) "
return myCell
//END ADDING ICONS
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
return "SEC | Starts | Ends | Building | Inst "
}
}
OUTPUT
这是我的项目链接,您可以使用它并测试它并自定义您想要的方式 https://drive.google.com/file/d/0B2csGr9uKp1DMWRhSjlCTWdFUEU/view?usp=sharing
关于ios - 将来自 API 的数组的数组信息显示为表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34523288/