0 Replies - 453 Views - Last Post: 30 November 2016 - 07:32 AM

#1 sas1205  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-October 15

Unexpected nil Value ?

Posted 30 November 2016 - 07:32 AM

Not quite sure what the error is but the main issue is the code here:


if revealViewController() != nil {
            menuButton.target =revealViewController()
            menuButton.action = "revealToggle:"
            view.addGestureRecognizer(self.revealViewController().pnGestureRecognizer())



Full code:

class DonateViewController: UIViewController {
    
    @IBOutlet weak var mainscrollView: UIScrollView!
    
    var imageArray = [UIImage]()
    
    @IBOutlet weak var tableView: UITableView!
    var model: [DonationFund]!
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
         if revealViewController() != nil {
            menuButton.target =revealViewController()
            menuButton.action = "revealToggle:"
            view.addGestureRecognizer(self.revealViewController().pnGestureRecognizer())

     
        imageArray = [#imageLiteral(resourceName: "333"),#imageLiteral(resourceName: "111"),#imageLiteral(resourceName: "222")]
        
        for i in 0..<imageArray.count{
            let imageView = UIImageView()
            imageView.image = imageArray[i]
            let xPosition = self.view.frame.width * CGFloat(i)
            imageView.frame = CGRect(x: xPosition, y: 0, width: self.mainscrollView.frame.width, height: self.mainscrollView.frame.height)
    
            mainscrollView.contentSize.width = mainscrollView.frame.width * CGFloat(i + 1)
            mainscrollView.addSubview(imageView)
        
        }
        
        let first = DonationFund(name: "General Fund", url: "https://paypal.com")
        let second = DonationFund(name: "Sacrifice Space Fund", url: "https://paypal.com")
        let third = DonationFund(name: "Building Fund", url: "https://paypal.com")
        let fourth = DonationFund(name: "Over 21 Club", url: "https://paypal.com")
        let fifth = DonationFund(name: "20/20 Campaign", url: "https://paypal.com")

        
        model = [first, second, third, fourth, fifth]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "Donate" {
            if let indexPath = tableView.indexPathForSelectedRow {
                let donationFund = model[indexPath.row]
                let viewController = segue.destination as! WebViewViewController
                viewController.title = donationFund.name
                viewController.url = donationFund.url
            }
        }
    }
}

extension DonateViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return model.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
        cell.name.text = model[indexPath.row].name
        return cell
    }
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1