首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在swift中为iphone构建tableView时出现错误

在swift中为iphone构建tableView时出现错误
EN

Stack Overflow用户
提问于 2014-12-17 05:00:50
回答 3查看 8.6K关注 0票数 10

嗨,我看了很多教程,最终为应用程序store.Recently创建了一个应用程序,我对tableViews产生了兴趣,所以我遵循了许多教程,似乎总是收到错误,而教程中的人却成功地构建了他们的应用程序。当我尝试运行我的应用程序时,构建过程停止了,并且在AppDelegate类中显示"class AppDelegate ...“的行上出现了一个异常。例外是“线程1:信号SIGABRT”

对于感兴趣的人,这里提供了控制台中的消息。

代码语言:javascript
运行
复制
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)  
EN

回答 3

Stack Overflow用户

发布于 2015-08-06 02:01:05

可能您想要使用的函数是

代码语言:javascript
运行
复制
tableView.registerClass(UITableViewController.self, forCellReuseIdentifier: cellIdentifier)

而不是

代码语言:javascript
运行
复制
tableView.registerClass(UITableViewController.self, forHeaderFooterViewReuseIdentifier: cellIdentifier)

希望就是这样。

票数 38
EN

Stack Overflow用户

发布于 2020-12-14 03:55:00

我认为这是一个小小的错误。

而不是:

代码语言:javascript
运行
复制
tableView.register(UITableView.self, forCellReuseIdentifier: "cell")

您需要使用:

代码语言:javascript
运行
复制
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")

请注意,寄存器函数中的第一个参数应该是UITableViewCell而不是UITableView

快乐编码:)

票数 6
EN

Stack Overflow用户

发布于 2014-12-18 00:01:11

我也受到了这个问题的困扰。

正如Paulw11所说,问题出在您的注册类方法调用上。

我按照pull to refresh教程进行操作,并让表格视图像这样工作:

我换掉了

代码语言:javascript
运行
复制
    var tableView = tableViewController.tableView

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

通过以下方式:

代码语言:javascript
运行
复制
var refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: Selector("sortArray"), forControlEvents: UIControlEvents.ValueChanged)
    self.refreshControl = refreshControl

...

func sortArray() {
    ...
}

启用拉取以刷新并允许我的代码运行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27513834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档