开发者

tableView in xib not picking up datasource delegate methods in associated view controller

开发者 https://www.devze.com 2023-03-27 22:34 出处:网络
My main xib file has a tab bar controller and each tab is linked to a different xib. One of the tabs is a nav controller and its view controller is linked to a xib as per this answer.

My main xib file has a tab bar controller and each tab is linked to a different xib.

One of the tabs is a nav controller and its view controller is linked to a xib as per this answer.

When I run the app I get the below error. its as if its not even looking in the view controller for these methods.

i have tried everything including using a different xib, checking the links in interface builder i.e. the tableview's delegate and datasource. i have implemented the required protocol methods in the vc e.g. numberofrowsinsection.

as soon as i remove the datasource link in the xib the error goes away.

EDIT: When I add this view controller's view to the main window (just to test) the tableview loads without issues. So it seems it only happens when I use it as part of the nav controller and tab controller.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6120ae0' * Call stack at first throw: ( 0 CoreFoundation

0x00dc45a9 exceptionPreprocess + 185 1 libobjc.A.dylib

0x00f18313 objc_exception_throw + 44 2 CoreFoundation

0x00dc60bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3

CoreFoundation 0x00d35966 __forwarding + 966 4 CoreFoundation 0x00d35522 _CF_forwarding_prep_0 + 50 5 UIKit

0x001d32b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834 6 UIKit

0x001d0d88 -[UITableViewRowData numberOfRows] + 108 7 UIKit

0x00084677 -[UITableView noteNumberOfRowsChanged] + 132 8 UIKit

0x00091708 -[UITableView reloadData] + 773 9 UIKit

0x0008e844 -[UITableView layoutSubviews] + 42 10 QuartzCore

0x016aea5a -[CALayer layoutSublayers] + 181 11 QuartzCore

0x016b0ddc CALayerLayoutIfNeeded + 220 12 QuartzCore

0x016560b4 _ZN2CA7Context18commit_transactionEPNS_11Transact开发者_如何学运维ionE + 310 13 QuartzCore 0x01657294 _ZN2CA11Transaction6commitEv + 292 14 QuartzCore

0x0165746d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99 15 CoreFoundation 0x00da589b CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27 16 CoreFoundation 0x00d3a6e7 __CFRunLoopDoObservers + 295 17 CoreFoundation 0x00d031d7 __CFRunLoopRun + 1575 18 CoreFoundation

0x00d02840 CFRunLoopRunSpecific + 208 19 CoreFoundation

0x00d02761 CFRunLoopRunInMode + 97 20 GraphicsServices

0x00ffc1c4 GSEventRunModal + 217 21 GraphicsServices

0x00ffc289 GSEventRun + 115 22 UIKit

0x00024c93 UIApplicationMain + 1160 23 MyPractice

0x00002339 main + 121 24 MyPractice

0x000022b5 start + 53 ) terminate called after throwing an instance of 'NSException'


This log message:

[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 

Implies that the UITableView dataSource method is being sent to an instance of UIViewController, not an instance of your subclass. How are you initialising your VC? If you're initialising it from within a XIB, have you correctly set the VC's class to your subclass?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号