2016-03-03 68 views
-3

我都需要使用数组 实例打印在实现代码如下数据: -打印数据迅速

var title = ["Java","C","C++"] 
var value = [["Inheritance","Not available","Inheritance"],["Polymorphism","Not Available","Polymorphism"],["Static","Dynamic","Static"]] 

如何打印上面的数据中的UITableView在迅速?下面

在UITableView的我都需要显示的数据定义方式: -

--------------------
Java继承
c不可
C++继承
-------------------
Java多态性
C不可用
C++多态性
--------------- ----
Java Static
C Dynamic
C++ Static

+0

请格式化你的问题。你试过了什么代码?它做错了什么? – Wain

+0

请在搜索问题之前先搜索如何编码UITableView并显示您的工作。在了解TableView的工作方式之后,剩下的只是一个for循环。 – Lee

回答

2

我不知道你的数据结构是最适合你想要达到什么 - 也许这将是更好

var sections = ["Inheritance", "Polymorphism", "Static"] 
var language = ["Java","C","C++"] 
var value = [["Not available","Inheritance"],["Not Available","Polymorphism"],["Dynamic","Static"]] 

假设你有一个简单的UITableView,与动态小区原型Cell ,那么您需要定义方法以返回节的数量,每节中的行数,节标题以及最终显示的单元格。

你可能会想使事情看起来比这更漂亮,但代码简单(不需要任何for循环)

func numberOfSectionsInTableView(tableView: UITableView) -> Int 
{ 
    return sections.count 
} 

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
{ 
    return "\(language[0]) \(sections[section])" 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    return language.count - 1 
} 


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") 

    cell?.textLabel!.text = "\(language[indexPath.row + 1]) \(value[indexPath.section][indexPath.row])" 

    return cell! 
} 

tableView