2016-05-06 10 views
0

マイViewControllerクラスは、私の問題は私のViewController doesntの負荷である。このAddingtblSettings.dataSource =自己

import UIKit 

class SubscriptionViewController:  
UIViewController,UITableViewDelegate, UITableViewDataSource { 

@IBOutlet weak var tblSettings: UITableView! 

@IBOutlet weak var vwTitle: UIView! 

let mutableDictionary = ["Business","News","Sports","Entertainment","Crime","Politics"] 

var imageView = UIImageView.init(frame: CGRectMake(0, 0, 20, 20)) 

override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view. 
    tblSettings.backgroundColor = UIColor.clearColor() 
    self.tblSettings.delegate = self 
    self.tblSettings.dataSource = self 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 


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

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    var cell = tableView.dequeueReusableCellWithIdentifier("SettingsCell") as! SettingsTableViewCell! 
    if cell == nil 
    { 
     //tableView.registerNib(UINib(nibName: "UICustomTableViewCell", bundle: nil), forCellReuseIdentifier: "UICustomTableViewCell") 
     tableView.registerClass(SettingsTableViewCell.classForCoder(), forCellReuseIdentifier: "SettingsCell") 

     cell = SettingsTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "SettingsCell") 

    } 
    cell.backgroundColor=UIColor.clearColor() 
    // Custom view options 
    let image=UIImage.init(named: "SettingsUnChecked") 

    imageView.image=image 

    cell.accessoryType = UITableViewCellAccessoryType.None 
    cell.accessoryView = imageView//UIButton(frame: CGRectMake(0, 0, 20, 20)) 

    cell.accessoryView!.backgroundColor = UIColor.clearColor() 

    if let label = cell.lblName{ 
     label.text = mutableDictionary[indexPath.row] 
     label.textColor=UIColor.whiteColor() 
    } 
    return cell 

} 


/* 
// MARK: - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
} 
*/ 

} 

のようなものであるのViewControllerをロードしません。しかし、私はtblSettings.datasource=self私のビューコントローラをコメントした場合に表示されます。いただきました!この理由?私を助けてください。 ありがとう

+0

私は、デリゲートは、テーブルビューの実装のためにOKだと思いますが、テーブルには 'self.tblSettings.reloadDataを(行うロードされていない場合は、コードでそれをやってデリゲート&データソース回避を割り当てるためにストーリーボードを使用してプラス)' viewDidLoad' –

+0

'に私はストーリーボードからデリゲートとデータソースを設定しようとしましたが、私は私のViewController doesntのappear.It両方がちょうどのViewControllerヘッダーまだ同じ – user1960169

+0

削除' UITableViewDataSource'で待機して設定すると問題があります。私のために動作しません:(まだ –

答えて

0

cellForRowAtIndexPathメソッドで汎用テーブルビューを参照している可能性がありますか?

試してみてください。

var cell = self.tblSettings.dequeueReusableCellWithIdentifier("SettingsCell") as! SettingsTableViewCell! 
+0

運:(私はあまりにも、登録部を変更 – user1960169