//
Tableviewcontroller.swift
2015.09TableView
//
Created by on 15/9/15.
Copyright (c) 2015 Leven. All rights reserved.
//
Import UIKit
Class tableviewcontroller:uitableviewcontroller{
var plistdata:nsdictionary!//dictionary has keys and values
var plistgroupname:nsarray!
Override Func Viewdidload () {
Super.viewdidload ()
Let Plistpath = Nsbundle.mainbundle (). Pathforresource ("Team_dictionary", OfType: "Plist")
Self.plistdata = Nsdictionary (contentsoffile:plistpath!)
var templist = Self.plistdata.allKeys as nsarray//all the key out of the attribute list file is cast to the array type.
Self.plistgroupname= Templist.sortedarrayusingselector ("compare:")//The number of nodes assigned to the order of the keys taken above
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
Dispose of any resources the can be recreated.
}
MARK:-Table View Data source
Override func Numberofsectionsintableview (Tableview:uitableview), Int {
Return self.plistgroupname.count//the number of sections in the table view is the number of sectionnum, and a plistgroupname in the property list file is a group
}
Override Func TableView (Tableview:uitableview, numberofrowsinsection a section with how many rows section:int), Int {
var groupname refers to a group B group, etc. = Self.plistgroupname[section] as string//here the Sectionnum has been assigned to the above, to obtain the result a group name, B group name
var listteams = Self.plistdata[groupname] As nsarray//here is a set of groups, through a group of names to find, by the B group name to find and so on; Get a list team, a listteams is a row
Return listteams.count//the number of rows in a section, we have 4 teams here, and we get the team number.
}
Override Func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), UITableViewCell {
Let Cellidentfier = "Cellidentifier"
var cell:customtableviewcell! = Tableview.dequeuereusablecellwithidentifier (cellidentfier) as? Customtableviewcell
if (cell = = nil) {
Cell = UITableViewCell (Style:UITableViewCellStyle.Default, Reuseidentifier:cellidentfier)
// }
Let section = Indexpath.section
Let row = Indexpath.row
Let GroupName = self.plistgroupname[section] as String
var listteam = Self.plistdata[groupname] as Nsarray
Cell.customlabel.text = Listteam[row] as? string//the whole paragraph is not very understanding, I hope to explain
//
Let ImagePath = nsstring (format: "%@.png", rowdict["image"] as String)
Cell.customimage.image = UIImage (Named:imagepath)
return cell
}
}
Block bar implementation added code to mark out