2014-12-16 21 views
6

HI Tôi xem nhiều hướng dẫn để cuối cùng tạo một ứng dụng cho kho ứng dụng. Tôi đã quan tâm đến tableViews vì vậy tôi đã làm theo nhiều hướng dẫn và dường như tôi luôn nhận được lỗi trong khi những người trong hướng dẫn thành công để xây dựng ứng dụng của họ. Khi tôi cố gắng chạy ứng dụng của mình, tòa nhà dừng lại và tôi nhận được ngoại lệ trong lớp AppDelegate trên dòng ghi "class AppDelegate ..." ngoại lệ là "Chủ đề 1: tín hiệu SIGABRT"tôi gặp lỗi khi cố gắng xây dựng một tableView nhanh chóng cho iphone

và cho những người quan tâm ở đây là thông điệp trong bảng điều khiển.

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) 
+0

Chạy ứng dụng với "Tất cả các trường hợp ngoại lệ" breakpoint và chỉ cho chúng ta nơi trong mã ngoại lệ xảy ra. – JAL

+1

Thông báo bàn điều khiển xuất hiện để mô tả chính xác vấn đề là gì. –

+2

Thông báo lỗi khá rõ ràng - lớp mà bạn đã chuyển đến 'registerClass: forHeaderFooterViewReuseIdentifier:' không phải là một lớp con của 'UITableViewHeaderFooterView' - kiểm tra nơi bạn gọi phương thức này và định nghĩa của lớp bạn đang đi qua – Paulw11

Trả lời

-1

Tôi cũng gặp phải vấn đề này.

Khi Paulw11 cho biết, sự cố là cuộc gọi phương thức đăng ký lớp học của bạn.

Tôi đi theo một kéo để làm mới hướng dẫn và nhận được những cái nhìn bàn làm việc như thế này:

tôi thay

var tableView = tableViewController.tableView 

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

với:

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

... 

func sortArray() { 
    ... 
} 

cho phép kéo để làm mới và cho phép mã của tôi chạy.

28

Có lẽ chức năng bạn muốn sử dụng là

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

thay vì

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

Hope đó là nó ...

+0

Bắt lỗi như SUPERMAN .... đã làm cho anh chàng ngày ... :) – Tuhin

Các vấn đề liên quan