gpt4 book ai didi

ios - swift : Exception while navigating UIViewController to UITableViewController

转载 作者:行者123 更新时间:2023-11-29 01:05:02 26 4
gpt4 key购买 nike

在 AppDelegate 中,我检查用户 session 列表是否移至用户主页(显示两个按钮),否则移至登录页面。登录后发送到用户主页后形成登录页面。

LoginView 是 UIViewControllerUserHome 是 UIViewController

当我在 UserHome 上单击“获取报告”时,我想在表格中显示一些报告ReportView 是 UITableViewController

这是应用程序代码

AppDelegate

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {


let mainStoryboard:UIStoryboard = UIStoryboard (name: "Main", bundle: nil)

let isUserLoggedIn:Bool = NSUserDefaults.standardUserDefaults().boolForKey("isUserLoggedIn")

if(!isUserLoggedIn){
let loginVC = mainStoryboard.instantiateViewControllerWithIdentifier("loginvc") as! LoginVC

window!.rootViewController = loginVC

window!.makeKeyAndVisible();

}else{

let userhome = mainStoryboard.instantiateViewControllerWithIdentifier("userhome") as! UserHomeViewController

window!.rootViewController = userhome
window!.makeKeyAndVisible();


}


return true
}

登录 View

rest服务响应成功后

let userhome = self.storyboard?.instantiateViewControllerWithIdentifier("user home") as! UserHomeViewController
dispatch_async(dispatch_get_main_queue()) {
self.presentViewController(userhome, animated: true, completion: nil)
}

获取报告我有

@IBAction func getReport(sender: UIButton) {

let reportview = self.storyboard?.instantiateViewControllerWithIdentifier("reportvc") as! ReportViewController

//Excepetion
self.presentViewController(reportview, animated: true, completion: nil)

//nothing happens
//self.navigationController?.presentViewController(reportview, animated: true, completion: nil)
}

ReportViewCOntroller 只是注意到了。实现的基本方法

class FSMSOListTableViewController: UITableViewController {

var soList = [String]()


override func viewDidLoad() {
super.viewDidLoad()

soList = ["E7677","E7678","E7679","E7680"]

self.tableView.registerClass(UITableView.self, forCellReuseIdentifier: "cell")


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return soList.count

}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(
"cell",
forIndexPath: indexPath) //make the cell

cell.textLabel?.text = self.soList[indexPath.row]

return cell
}

异常(exception)是

2016-04-09 12:26:19.415 AkunaConnect[13163:943688] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'must pass a class of kind UITableViewCell' * First throw call stack: ( 0 CoreFoundation 0x0000000102cf9e65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000104a39deb objc_exception_throw + 48 2 CoreFoundation 0x0000000102cf9d9d +[NSException raise:format:] + 205 3 UIKit 0x0000000103662b01 -[UITableView registerClass:forCellReuseIdentifier:] + 285 4 AkunaConnect 0x0000000102ad783f _TFC12AkunaConnect28FSMSOListTableViewController11viewDidLoadfS0_FT_T_ + 623 5 AkunaConnect 0x0000000102ad78f2 _TToFC12AkunaConnect28FSMSOListTableViewController11viewDidLoadfS0_FT_T_ + 34 6 UIKit 0x00000001036acf98 -[UIViewController loadViewIfRequired] + 1198 7 UIKit 0x00000001036ad2e7 -[UIViewController view] + 27 8 UIKit 0x0000000103e57f87 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87 9 UIKit 0x000000010367cf62 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133 10 UIKit 0x00000001036bfc8c -[UIViewController _presentViewController:withAnimationController:completion:] + 4002 11 UIKit 0x00000001036c2f2c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 489 12 UIKit 0x00000001036c2a3b -[UIViewController presentViewController:animated:completion:] + 179 13 AkunaConnect 0x0000000102ad688d _TFC12AkunaConnect17FLMViewController9getReportfS0_FCSo8UIButtonT_ + 621 14 AkunaConnect 0x0000000102ad69ea _TToFC12AkunaConnect17FLMViewController9getReportfS0_FCSo8UIButtonT_ + 58 15 UIKit 0x0000000103518194 -[UIApplication sendAction:to:from:forEvent:] + 92 16 UIKit 0x00000001036876fc -[UIControl sendAction:to:forEvent:] + 67 17 UIKit 0x00000001036879c8 -[UIControl _sendActionsForEvents:withEvent:] + 311 18 UIKit 0x0000000103686af8 -[UIControl touchesEnded:withEvent:] + 601 19 UIKit 0x000000010358749b -[UIWindow _sendTouchesForEvent:] + 835 20 UIKit 0x00000001035881d0 -[UIWindow sendEvent:] + 865 21 UIKit 0x0000000103536b66 -[UIApplication sendEvent:] + 263 22 UIKit 0x0000000103510d97 _UIApplicationHandleEventQueue + 6844 23 CoreFoundation 0x0000000102c25a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 24 CoreFoundation 0x0000000102c1b95c __CFRunLoopDoSources0 + 556 25 CoreFoundation 0x0000000102c1ae13 __CFRunLoopRun + 867 26 CoreFoundation 0x0000000102c1a828 CFRunLoopRunSpecific + 488 27 GraphicsServices 0x000000010730fad2 GSEventRunModal + 161 28 UIKit 0x0000000103516610 UIApplicationMain + 171 29 AkunaConnect 0x0000000102ad96cd main + 109 30 libdyld.dylib 0x000000010554292d start + 1 31 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

最佳答案

您正在尝试将 tableview 类实例注册为 ** FSMSOListTableViewController** 类中的 UITableViewCell。

这可能对您有帮助:

override func viewDidLoad() {
super.viewDidLoad()
soList = ["E7677","E7678","E7679","E7680"]
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

}

关于ios - swift : Exception while navigating UIViewController to UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36513773/

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