[翻译]  i get an error when trying to build a tableView in swift for iphone

[CHINESE]  我试图在swift for iphone中构建一个tableView时出错


HI I watch many tutorials to finally create an app for the app store.Recently I got interested by tableViews so I followed many tutorials and I seem to always get an error whereas the people in the tutorial succeed to build their app . When I try to run my app , the building stops and I get an exception in the AppDelegate class on the line where it says "class AppDelegate ..." the exception is "Thread 1 : signal SIGABRT"

我看了很多教程,最终为应用程序商店创建了一个应用程序。最后我对tableViews感兴趣,所以我遵循了许多教程,我似乎总是得到一个错误,而教程中的人们成功构建他们的应用程序。当我尝试运行我的应用程序时,构建停止,我在AppDelegate类中得到一个异常,它在该行中显示“class AppDelegate ...”异常是“Thread 1:signal SIGABRT”

and for those interested here is the message in the console .

对于那些感兴趣的人是控制台中的消息。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'must pass a class of kind UITableViewHeaderFooterView'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000109c80f35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010b7c4bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000109c80e6d +[NSException raise:format:] + 205
    3   UIKit                               0x000000010a5fb254 -[UITableView registerClass:forHeaderFooterViewReuseIdentifier:] + 247
    4   tableviewtes                        0x0000000109a9cc3c _TFC12tableviewtes14ViewController11viewDidLoadfS0_FT_T_ + 460
    5   tableviewtes                        0x0000000109a9ccd2 _TToFC12tableviewtes14ViewController11viewDidLoadfS0_FT_T_ + 34
    6   UIKit                               0x000000010a631a90 -[UIViewController loadViewIfRequired] + 738
    7   UIKit                               0x000000010a631c8e -[UIViewController view] + 27
    8   UIKit                               0x000000010a550ca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
    9   UIKit                               0x000000010a551041 -[UIWindow _setHidden:forced:] + 247
    10  UIKit                               0x000000010a55d72c -[UIWindow makeKeyAndVisible] + 42
    11  UIKit                               0x000000010a508061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
    12  UIKit                               0x000000010a50ad2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
    13  UIKit                               0x000000010a509bf2 -[UIApplication workspaceDidEndTransaction:] + 179
    14  FrontBoardServices                  0x000000010d3512a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    15  CoreFoundation                      0x0000000109bb653c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    16  CoreFoundation                      0x0000000109bac285 __CFRunLoopDoBlocks + 341
    17  CoreFoundation                      0x0000000109bac045 __CFRunLoopRun + 2389
    18  CoreFoundation                      0x0000000109bab486 CFRunLoopRunSpecific + 470
    19  UIKit                               0x000000010a509669 -[UIApplication _run] + 413
    20  UIKit                               0x000000010a50c420 UIApplicationMain + 1282
    21  tableviewtes                        0x0000000109a9faee top_level_code + 78
    22  tableviewtes                        0x0000000109a9fb2a main + 42
    23  libdyld.dylib                       0x000000010bf9e145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)  

2 个解决方案

#1


30  

Probably the function you want to use is

可能你想要使用的功能是

tableView.registerClass(UITableViewController.self, forCellReuseIdentifier: cellIdentifier)

instead of

代替

tableView.registerClass(UITableViewController.self, forHeaderFooterViewReuseIdentifier: cellIdentifier)

Hope that's it ...

希望就是这样......

#2


-1  

I too suffered from this problem.

我也遇到了这个问题。

As Paulw11 said, the problem is your register class method call.

正如Paulw11所说,问题是你的寄存器类方法调用。

I followed a pull to refresh tutorial and got the table view working like this:

我按照一个拉动刷新教程,让表视图像这样工作:

I replaced

我换了

    var tableView = tableViewController.tableView

    tableView.registerClass(UITableViewController.self, forHeaderFooterViewReuseIdentifier: cellIdentifier)

with:

有:

var refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: Selector("sortArray"), forControlEvents: UIControlEvents.ValueChanged)
    self.refreshControl = refreshControl

...

func sortArray() {
    ...
}

enabling pull to refresh and allowing my code to run.

启用pull刷新并允许我的代码运行。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号