0
我作爲示例文件從Github ENSwiftSideMenu下載,以獲取可用菜單的提示,MyMenuTableViewController.swift文件MyMenuTableViewController.swift我想更改在菜單中的單元格,但我堅持在代碼的一部分之後。感謝大家的幫助。薩爾瓦多更改菜單單元格的標籤的文本
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CELL")
cell!.backgroundColor = UIColor.clearColor()
cell!.textLabel?.textColor = UIColor.darkGrayColor()
let selectedBackgroundView = UIView(frame: CGRectMake(0, 0, cell!.frame.size.width, cell!.frame.size.height))
selectedBackgroundView.backgroundColor = UIColor.grayColor().colorWithAlphaComponent(0.2)
cell!.selectedBackgroundView = selectedBackgroundView
}
cell!.textLabel?.text = "CELL \(indexPath.row+1)"
return cell!
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50.0
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("did select row: \(indexPath.row)")
if (indexPath.row == selectedMenuItem) {
return
}
selectedMenuItem = indexPath.row
//Present new view controller
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
var destViewController : UIViewController
switch (indexPath.row) {
case 0:
destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Home") as UIViewController
break
case 1:
destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Profilo") as UIViewController
break
case 2:
destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Notizie") as UIViewController
break
default:
destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Impostazioni") as UIViewController
break
}
sideMenuController()?.setContentViewController(destViewController)
}
謝謝您立即作出反應,我誆騙這個東西代替上面的代碼,但我還有一個問題,我添加了一個額外的列來包含圖像,因爲我插入選擇的圖像以匹配字符串? 在此先感謝您的幫助。 – 2014-10-01 11:33:49