2016-08-16 90 views
1

我在一個UIViewController(不是UITableViewController)的tableview中有兩個表。現在我只想讓其中一個單元添加UITableViewCellAccessoryDisclosureIndicator讓用戶點擊查看另一個tableview。Swift:添加UITableViewCellAccessoryDisclosureIndicator並鏈接到另一個tableview

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell = UITableViewCell() 
    if indexPath.section == 0{ 
     cell.textLabel?.text = "\(rentTitle[indexPath.row]): \(rentArray[indexPath.row])" 
    }else{ 
     cell.textLabel?.text = "\(cashflowTitle[indexPath.row]): \(cashflowArray[indexPath.row])" 
    } 
    return cell 
} 

第一個表格中有6行,第二個表格中有5行。我想在第二個表的第三行添加disclosureIndicator。所以問題是:1.如何在第二個表的第三行添加披露指示符? 2.如何使該行主動鏈接到另一個tableView?非常感謝!

func tableView(tableView: UITableView,accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath){ 
    var cell = UITableViewCell() 
    if indexPath.section == 1{ 
     if indexPath.row == 2{ 
      print(indexPath.row) 
     } 
    } 
} 

我試着先打印。

回答

0

該箭頭不是UINavigationItem;它是一個UITableViewCellAccessoryDisclosureIndicator。

爲此UITableViewCellAccessoryDisclosureIndicator「箭頭」添加到您的細胞的附件查看,添加這一行:

if indexPath.row == 2 { //Third row 
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 
} 

然後當附件視圖抽頭執行特定的動作,實現

的tableView :accessoryButtonTappedForRowWithIndexPath:

在此方法中通過檢查索引來實現您的導航再次路徑。

+0

謝謝你的回覆。我已經解決了指標。但是,如何在「tableView:accessoryButtonTappedForRowWithIndexPath:」中添加動作? – user6702783

+0

這是一種類似於'cellForRowAtIndex'的委託方法。以相同的方式實施輕拍按鈕。 – Harsh

+0

我使用UIViewController而不是UITableViewController。故事板可能有點不同,UIViewController中沒有「原型單元」。我試過「var cell」並再次檢查indexPath,但不起作用。 – user6702783

相關問題