gpt4 book ai didi

ios - 添加tblSettings.dataSource = self不会加载 View Controller

转载 作者:行者123 更新时间:2023-11-30 13:26:58 25 4
gpt4 key购买 nike

我的ViewController类是这样的

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.
}
*/

}

我的问题是我的 View Controller 未加载。但是如果我评论 tblSettings.datasource=self 我的 View Controller 就会出现。这是什么原因呢?请帮我。谢谢

最佳答案

这可能是因为在您的 cellForRowAtIndexPath 方法中您引用了通用表格 View 吗?

尝试:

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

关于ios - 添加tblSettings.dataSource = self不会加载 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37064996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com