[英]how to display collectionview in second view when i tap on tableview any cell in first view
[英]cell not replacing when i tap any cell in table view
我有一个开关控件,该代码是:
@IBAction func TappedOnSwitch(SelectUserType: UISwitch) {
if SelectUserType.on{
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "PremiumUser")
print("swifth on")
}
else
{
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "normalUser")
print("swifth off")
}
}
它在我的控制台中打印得很好。 然后我检查这个开关状态并替换我的表格视图中的单元格。
但它工作得不好。 我需要的是什么? 当开关接通时,我需要显示cell3
,当我关掉我需要显示cell2
。通过默认cell
显示在表浏览显示
这是我的代码:
let premiumUserCheck = NSUserDefaults.standardUserDefaults().boolForKey("PremiumUser")
覆盖 func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.jsonParsingFromURL()
let nib = UINib(nibName:"customCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "cell")
let nib1 = UINib(nibName:"Expandcell", bundle: nil)
tableView.registerNib(nib1, forCellReuseIdentifier: "cell2")
let nib2 = UINib(nibName:"premiumUsercell", bundle: nil)
tableView.registerNib(nib2, forCellReuseIdentifier: "cell3")
}
更新代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if(isTapped == true && indexPath == selectedIndex)
{
if (premiumUserCheck ) {
let cell1:premiumUsercell = self.tableView.dequeueReusableCellWithIdentifier("cell3") as! premiumUsercell
cell1.vendorName3.text=arrDict[indexPath.section] .valueForKey("name") as? String
cell1.vendorAdddress3.text=arrDict[indexPath.section] .valueForKey("address") as? String
return cell1
print("premium user")
}
else {
let cell2:ExpandCell = self.tableView.dequeueReusableCellWithIdentifier("cell2") as! ExpandCell
cell2.VendorName.text=arrDict[indexPath.section] .valueForKey("name") as? String
cell2.vendorAdress.text=arrDict[indexPath.section] .valueForKey("address") as? String
cell2.externalView.hidden = true
print("non premium user")
return cell2
}
}
else {
let cell:customCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! customCell
cell.vendorName.text=arrDict[indexPath.section] .valueForKey("name") as? String
cell.vendorAddress.text=arrDict[indexPath.section] .valueForKey("address") as? String
return cell
print("norml user")
}
}
请帮我看看为什么它没有正确更换??
尝试更改您的代码如下,
if SelectUserType.on{
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "PremiumUser")
NSUserDefaults.standardUserDefaults().synchronize()
print("swifth on")
} else {
//Here you were setting value for normalUser key instead of PremiumUser
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "PremiumUser"/*"normalUser"*/)
NSUserDefaults.standardUserDefaults().synchronize()
print("swifth off")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.