在AppDelegate中,我检查用户会话列表是否移动到用户主页(显示两个按钮)否则登录页面。登录后发送到用户主页的表单登录页面。
LoginView是UIViewController
UserHome是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
}
LoginView
来自休息服务的成功回复后
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
}
例外
2016-04-09 12:26:19.415 AkunaConnect [13163:943688] *由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:'必须通过一类UITableViewCell的' * 第一次抛出调用堆栈: ( 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视图] + 27 8 UIKit 0x0000000103e57f87 - [_ UIFullscreenPresentationController _setPresentedViewController:] + 87 9 UIKit 0x000000010367cf62 - [UIPresentationController initWithPresentedViewController:presentsViewController:] + 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:以NSException类型的未捕获异常终止 (lldb)
答案 0 :(得分:1)
您正尝试在** FSMSOListTableViewController **类中将tableview类实例注册为UITableViewCell。
这可以帮助您:
override func viewDidLoad() {
super.viewDidLoad()
soList = ["E7677","E7678","E7679","E7680"]
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}