Tableview控制器错误

时间:2016-12-10 08:31:42

标签: swift uitableview

您好我在运行表视图控制器时遇到以下错误。 我试图在UITableViewController中显示一些带编码的文本。

    *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e79134b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010baab21e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010e7e9bdf -[__NSSingleObjectArrayI objectAtIndex:] + 111
    3   UIKit                               0x000000010c738fe9 -[UITableViewDataSource tableView:heightForRowAtIndexPath:] + 181
    4   UIKit                               0x000000010c39c06b -[UITableViewController tableView:heightForRowAtIndexPath:] + 63
    5   UIKit                               0x000000010c0f1d7e -[UITableView _dataSourceHeightForRowAtIndexPath:] + 99
    6   UIKit                               0x000000010c32bac6 __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 368
    7   UIKit                               0x000000010c32b081 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 3375
    8   UIKit                               0x000000010c330d31 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 501
    9   UIKit                               0x000000010c330e8f -[UITableViewRowData heightForTable] + 56
    10  UIKit                               0x000000010c0b2f36 -[UITableView _updateContentSize] + 381
    11  UIKit                               0x000000010c0db46f -[UITableView _rebuildGeometry] + 40
    12  UIKit                               0x000000010c0d96e3 -[UITableView setLayoutMargins:] + 282
    13  UIKit                               0x000000010c0d95a7 -[UITableView _setDefaultLayoutMargins:] + 103
    14  UIKit                               0x000000010c1127dc -[UIViewController _setContentOverlayInsets:] + 646
    15  UIKit                               0x000000010c112de2 -[UIViewController _updateContentOverlayInsetsFromParentIfNecessary] + 1000
    16  UIKit                               0x000000010c112859 -[UIViewController _updateContentOverlayInsetsForSelfAndChildren] + 101
    17  UIKit                               0x000000010c11e2d8 -[UIViewController _updateLayoutForStatusBarAndInterfaceOrientation] + 1027
    18  UIKit                               0x000000010c124002 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 1238
    19  UIKit                               0x000000010c038620 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1590
    20  UIKit                               0x000000010c0500e2 -[UIScrollView _didMoveFromWindow:toWindow:] + 85
    21  UIKit                               0x000000010c02b6b4 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
    22  UIKit                               0x000000010c02b5a2 -[UIView(Hierarchy) _postMovedFromSuperview:] + 857
    23  UIKit                               0x000000010c03b2eb -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1982
    24  UIKit                               0x000000010c0297a1 -[UIView(Hierarchy) addSubview:] + 838
    25  UIKit                               0x000000010bfe5f5b -[UIWindow addRootViewControllerViewIfPossible] + 849
    26  UIKit                               0x000000010bfe63a2 -[UIWindow _setHidden:forced:] + 293
    27  UIKit                               0x000000010bff9cb5 -[UIWindow makeKeyAndVisible] + 42
    28  UIKit                               0x000000010bf72c89 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
    29  UIKit                               0x000000010bf78de9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
    30  UIKit                               0x000000010bf75f69 -[UIApplication workspaceDidEndTransaction:] + 188
    31  FrontBoardServices                  0x000000011468a723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    32  FrontBoardServices                  0x000000011468a59c -[FBSSerialQueue _performNext] + 189
    33  FrontBoardServices                  0x000000011468a925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    34  CoreFoundation                      0x000000010e736311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    35  CoreFoundation                      0x000000010e71b59c __CFRunLoopDoSources0 + 556
    36  CoreFoundation                      0x000000010e71aa86 __CFRunLoopRun + 918
    37  CoreFoundation                      0x000000010e71a494 CFRunLoopRunSpecific + 420
    38  UIKit                               0x000000010bf747e6 -[UIApplication _run] + 434
    39  UIKit                               0x000000010bf7a964 UIApplicationMain + 159
    40  swift_mvp                           0x000000010b2dec2f main + 111
    41  libdyld.dylib                       0x000000010f6c468d start + 1
    42  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我正在尝试运行简单的TableView控制器

表视图控制器的代码如下:

import Foundation
import UIKit


class FeedsTableViewController: UITableViewController, UserView {

    private var userPresenter: UserPresenter?

    override func viewDidLoad() {
        super.viewDidLoad()
        userPresenter = UserPresenter(userView: self)
        //userPresenter?.getUsers()
    }


    func startLoading() {
        print("Loading started")
    }

    func stopLoading() {
        print("Stop loading")
    }

    func onEmpty() {
        print("No users available")
    }

    func onUsers(users: [User]) {
        print("Users \(users.count)")
    }


    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print("number of section row fine")
        return 10
    }

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

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        print("number Getting item")
        let cellItem = tableView.dequeueReusableCell(withIdentifier: "USER_ITEM_ROW", for: indexPath)
        //cellItem.textLabel?.text = "sdadas"
        return cellItem
    }


}

0 个答案:

没有答案