下面的代碼:如何在表格視圖中使用單元格的標識符?
import UIKit
class SliderMenuTableViewController: UITableViewController {
var tableArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
let age: String
age = String(LoginViewController.AGE)
let Profile = LoginViewController.NAME! + ", " + age
tableArray = [Profile,"Second","Third","Fourth","Logout"]
}
// table view delegate method
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier(tableArray[indexPath.row], forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = tableArray[indexPath.row]
if cell.textLabel?.text == tableArray[0] {
cell.imageView?.frame = CGRectMake(10, 10, 50, 50)
cell.imageView!.layer.borderWidth = 1
cell.imageView!.layer.masksToBounds = false
cell.imageView!.layer.borderColor = UIColor.blackColor().CGColor
cell.imageView!.layer.cornerRadius = cell.imageView!.frame.width/2
cell.imageView!.clipsToBounds = true
cell.imageView?.image = LoginViewController.AVATAR
}
return cell
}
時出錯:
終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「不能出列與標識尤,可選電池(29) - 必須註冊一個筆尖或類的標識符或連接故事板中的原型單元
我知道我必須標識單元格,如何從代碼中執行此操作會導致變量'Profile'在我的tableArray
中不是靜態的,我不能從故事板標識它?
在Interface Builder中將表格視圖單元格拖入表格視圖。然後你可以添加標識符。 – vadian