gpt4 book ai didi

ios - Swift 无法识别的选择器发送到导航栏上的实例错误

转载 作者:行者123 更新时间:2023-11-28 13:07:35 26 4
gpt4 key购买 nike

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyApp.DetailPage saveit]: unrecognized selector sent to instance 0x13c539ed0'

我已将导致此错误的代码加粗。任何建议表示赞赏!

import UIKit

class DetailPage: UIViewController, UIPageViewControllerDataSource {

// MARK: - Variables
private var pageViewController: UIPageViewController?
var TableData:Array< String > = Array < String >()

var company_name: String?
var webSite: String?

var object: PFObject!

// Initialize it right away here

private let contentWeb = ["http://www.example.com/chart1.php",
"http://www.example.com/app/chart2.php",
"http://www.example.com/app/chart3.php",
"http://www.example.com/chart4.php"]

// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()

// Test out programically setting navigation bar
let sendButton = UIBarButtonItem(title: "Save", style: UIBarButtonItemStyle.Plain, target: self, action: "saveit")
self.navigationItem.rightBarButtonItem = sendButton

createPageViewController()
setupPageControl()

}

private func createPageViewController() {

let pageController = self.storyboard!.instantiateViewControllerWithIdentifier("PageController") as! UIPageViewController
pageController.dataSource = self

if contentWeb.count > 0 {
let firstController = getItemController(0)!
let startingViewControllers: NSArray = [firstController]
pageController.setViewControllers(startingViewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}

pageViewController = pageController
addChildViewController(pageViewController!)
self.view.addSubview(pageViewController!.view)
pageViewController!.didMoveToParentViewController(self)
}

private func setupPageControl() {
let appearance = UIPageControl.appearance()
appearance.pageIndicatorTintColor = UIColor.grayColor()
appearance.currentPageIndicatorTintColor = UIColor.whiteColor()
appearance.backgroundColor = UIColor.darkGrayColor()
}

// MARK: - UIPageViewControllerDataSource

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {

let itemController = viewController as! PageItemController

if itemController.itemIndex > 0 {
return getItemController(itemController.itemIndex-1)
}

return nil
}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {

let itemController = viewController as! PageItemController

if itemController.itemIndex+1 < contentWeb.count {
return getItemController(itemController.itemIndex+1)
}

return nil
}

private func getItemController(itemIndex: Int) -> PageItemController? {

if itemIndex < contentWeb.count {
let pageItemController = self.storyboard!.instantiateViewControllerWithIdentifier("ItemController") as! PageItemController
pageItemController.itemIndex = itemIndex
// pageItemController.imageName = contentImages[itemIndex]
pageItemController.webSite = TableData[itemIndex]

return pageItemController
}

return nil
}

// MARK: - Page Indicator

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return contentImages.count
}

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)

}

func saveit(sender: AnyObject) {

self.object["username"] = PFUser.currentUser()!.username
self.object["company_name"] = company_name
self.object["email"] = PFUser.currentUser()!.email


self.object.saveEventually { (success, error) -> Void in

if (error == nil) {

}else {

println(error!.userInfo)

}

}

self.navigationController?.popToRootViewControllerAnimated(true)

}



}

最佳答案

改变:

 let sendButton = UIBarButtonItem(title: "Save", style: UIBarButtonItemStyle.Plain, target: self, action: "saveit")

收件人:

let sendButton = UIBarButtonItem(title: "Save", style: UIBarButtonItemStyle.Plain, target: self, action: "saveit:")

或者删除 saveit 方法中的 sender: AnyObject

关于ios - Swift 无法识别的选择器发送到导航栏上的实例错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32239519/

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