2015-02-11 27 views
-1

我有近30個單元被佔用在我的UITableView中。我使用故事板模式創建表格。當我試圖調用我選擇其註冊爲0的單元格時,無論我選擇了哪個單元格。如何讓我的手機註冊我推送的確切號碼並將其插入到我的當前標籤中? 這裏是我迄今爲止我的UITableView單元沒有給我正確的信息

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell 

     cell.textLabel?.text = catNames[indexPath.row] 
     cell.textLabel?.textColor = UIColor.whiteColor() 
     cell.backgroundColor = UIColor(red: 0x0e/255, green: 0x1b/255, blue: 0x35/255, alpha: 1.0) 
     cell.textLabel?.textAlignment = NSTextAlignment.Left 
     cell.textLabel?.lineBreakMode = NSLineBreakMode.ByTruncatingMiddle 
     cell.textLabel?.adjustsFontSizeToFitWidth = true 
     return cell 
    } 

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

     currentTag = tableView.tag 
     println("This is the \(currentTag)") 
     self.performSegueWithIdentifier("table2Segue", sender:self) 

    } 
+1

使用'currentTag = indexPath.row'。除非將其設置爲其他值,否則您的'tableView'將始終具有'tag'作爲'0'。 – sikhapol 2015-02-11 18:31:01

回答

1

NSIndexPath提供表格視圖選擇的部分和行。

與您如何通過catNames[indexPath.row]設置單元格文本類似,您應該使用indexPath.row來確定被點擊的單元格的索引。

因此:

currentTag = indexPath.row; 
+0

哦,好的!很高興知道背後的邏輯!謝謝 – Tom 2015-02-11 18:42:16

2

使用indexPath.row找出哪個單元。如果你有部分,你也需要使用indexPath.section

+0

是的,這是我發現我做錯了,導致與indexPath.row衝突。謝謝!! – Tom 2015-02-11 18:38:46

相關問題