2015-12-19 26 views
1

我有一個navigationController,我已經添加了一個自定義的UIBarButtonItem。我想要做的是當用戶點擊我的按鈕時,它會呈現一個viewController,其中有一個tableView。意外發現無線上tableView.datasourse = self

對於這一點,我寫了這個:

let shopoingCarVC:shopingCartProductsList = shopingCartProductsList() 
self.navigationController?.pushViewController(shopoingCarVC, animated: true) 

shopingCartProductsList是我的ViewController我打算導航到,當它定位到它給了我意外發現零誤差在這一行:

tableViewProducts.dataSource = self 

我已經在我的其他viewControllers之前完成了它,但是在導航時沒有使用segue並使用pushViewController mehod時出現此問題。

這是我targetViewCOntroller:

import UIKit 
import Alamofire 
import Haneke 

class shopingCartProductsList: BaseViewController ,UITableViewDataSource, UITableViewDelegate { 


    @IBOutlet weak var ShopingCartProducts: UITableView! 

    var products = dataService.instance.shopingCartProduct 
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 

    } 



    override func viewDidLoad() { 
     super.viewDidLoad() 
     ShopingCartProducts.dataSource = self 
     ShopingCartProducts.delegate = self 
     self.view.backgroundColor = COLOR_BACKGROUND 

    } 




func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    if let tblCell = tableView.dequeueReusableCellWithIdentifier("shopingCart_cell") as? shopingCart_cell { 
     if let prod = products[indexPath.row] as? productMD{ 
      tblCell.configCell(prod) 
     } 
     return tblCell 
    }else{ 
     return shopingCart_cell() 
    } 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    print("products count \(products.count)") 
    return products.count 
} 



     func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
      return 1 
     } 


    } 

有什麼不對?

+0

請確保您已將tableview數據源和委託方法連接到主視圖並實現了所需的委託和數據源方法。 – sourav

+0

@AvijitNagare,我編輯了我的問題。這是我迄今爲止所做的工作 – sali

+0

@sourav我編輯了我的問題。檢查完整的ViewController源代碼。 – sali

回答

0

將viewcontroller用戶下面的代碼推向使用是錯誤的。在身份檢查

let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("LoginViewController") as LoginViewController self.navigationController?.pushViewController(secondViewController, animated: true) 

enter image description here

集標識符。