我如何通过应用内购买锁定在一个特定的tableview行?

问题描述 投票:0回答:1

我有需要的用户才能访问其内容支付的tableview。然而,整个tableview中被锁定。我想有,例如,前两行锁定,同时第三排锁定。我也有其他的tableviews超过12行的他们,只是张贴了现在这个视图控制器。我通过阵列喂养我的数据,我已经在应用内购买成立。这里是我当前的代码:

import Foundation
import UIKit

class TrappingVC: UIViewController {


@IBOutlet weak var buildingTableView: UITableView!
@IBOutlet weak var settingsButtonItem: UIBarButtonItem!

var trapping: [CellObject] = []
var segueIdentifiers = ["a", "b"]


//VIEWDIDLOAD

override func viewDidLoad() {
    super.viewDidLoad()


    //LOAD ARRARYS
    trapping = createBuildArray()

    buildingTableView.delegate = self
    buildingTableView.dataSource = self

    self.buildingTableView.rowHeight = 100.0
    buildingTableView.tableFooterView = UIView()

    //CELL SEPARATORS
    buildingTableView.layoutMargins = UIEdgeInsets.zero
    buildingTableView.separatorInset = UIEdgeInsets.zero
    buildingTableView.separatorColor = UIColor.black

    buildingTableView.register(UINib.init(nibName: "TrappingCell", bundle: nil), forCellReuseIdentifier: "TrappingCell")

    settingsButtonItem.image = UIImage(named: "Settings")


}

@IBAction func showSettingsClicked(_ sender: Any) {
    performSegue(withIdentifier: "showSettings", sender: self)
}




//CREATE ARRAY OF BASIC LESSONS
func createBuildArray() -> [CellObject]{

    var tempTrapping: [CellObject] = []

    let trapping1 = CellObject(image: #imageLiteral(resourceName: "Yellow"), title: "Below")
    let trapping2 = CellObject(image: #imageLiteral(resourceName: "Yellow"), title: "Side")
    let trapping3 = CellObject(image: #imageLiteral(resourceName: "Yellow"), title: "Above")



    tempTrapping.append(trapping1)
    tempTrapping.append(trapping2)
    tempTrapping.append(trapping3)



    return tempTrapping
}


}






//TABLE

extension TrappingVC: UITableViewDataSource, UITableViewDelegate {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return trapping.count

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let trappings = trapping[indexPath.row]

    let cell = tableView.dequeueReusableCell(withIdentifier: "TrappingCell") as! TrappingCell

    cell.trappingTitle.text = trappings.title
    cell.trappingImage.image = trappings.image

    if let purchased = UserDefaults.standard.value(forKey: "payment") as? Bool{
        if purchased == true{
            cell.lockedImage.isHidden = true
        }else{
            cell.lockedImage.isHidden = false
        }
    }else{
        cell.lockedImage.isHidden = false
    }


    cell.layoutIfNeeded()
    cell.layoutMargins = UIEdgeInsets.zero

    return cell

}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if let purchased = UserDefaults.standard.value(forKey: "payment") as? Bool{
        if purchased == true{
            performSegue(withIdentifier: segueIdentifiers[indexPath.row], sender: self)
        }else{
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let controller = storyboard.instantiateViewController(withIdentifier: "UnlockContentVC")

            self.navigationController?.pushViewController(controller, animated: true)
        }
    }else{
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "UnlockContentVC")

        self.navigationController?.pushViewController(controller, animated: true)
    }

    tableView.deselectRow(at: indexPath, animated: true)

}

}
ios swift xcode tableview storekit
1个回答
0
投票

我用下面的代码固定它:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let purchased = UserDefaults.standard.value(forKey: "payment") as? Bool

    if indexPath.row < 5 {
        performSegue(withIdentifier: segueIdentifiers[indexPath.row], sender: self)
    }

    else if purchased == true {
        performSegue(withIdentifier: segueIdentifiers[indexPath.row], sender: self)
    } else {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "UnlockContentVC")

        self.navigationController?.pushViewController(controller, animated: true)
    }

    tableView.deselectRow(at: indexPath, animated: true)

}
© www.soinside.com 2019 - 2024. All rights reserved.