Problem with UITableView as a preview in NIB

Executive summary: I am trying to use UITableViewmy main window as a subquery; it appears, but when I scroll the window, I get the following error message:

2010-11-20 17:17:51.958 xwtf[6997:207] -[NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x5f46550

I have a subclass ViewControllerwith the corresponding NIB file that is loaded by my application delegate. This is your typical new project template. In this NIB file, I add UITableViewas a subview submission. In Interface Builder, I occupy it the size of the entire window (i.e. completely overlaps its parent view).

Now I need to specify the data source and the delegate. I create a class with the name DumbTableHelperas follows:

@interface DumbTableHelper : NSObject<UITableViewDelegate, UITableViewDataSource> {
}

So this is not a subclass UIViewController, but I am trying to keep it simple - all I need is a delegate and a data source that it can call to, right? Besides dealloc, my methods in the .m file:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
  return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *CellIdentifier = @"DumbTableCell";
  UITableViewCell *cell = [tableView
                           dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                     reuseIdentifier:CellIdentifier]
            autorelease];
  }
  return cell;
}

As you can see, I am not even setting up any cell; I just specify 10 lines, which is enough to force scroll. In any case, in Interface Builder, I drag an object from the library to my NIB. Then I change the name of my class to DumbTableHelperand point it as the data source and the delegate from UITableViewthere already. When I run it, a table will appear. When I try to scroll down in a table, I get:

010-11-20 18:19:54.673 xwtf[6997:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x5f46550'
*** Call stack at first throw:
(
0   CoreFoundation                      0x0259eb99 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x0239340e objc_exception_throw + 47
2   CoreFoundation                      0x025a06ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3   CoreFoundation                      0x025102b6 ___forwarding___ + 966
4   CoreFoundation                      0x0250fe72 _CF_forwarding_prep_0 + 50
5   UIKit                               0x00321d6f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 619
6   UIKit                               0x00317e02 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
7   UIKit                               0x0032c69f -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1348
8   UIKit                               0x003247ec -[UITableView layoutSubviews] + 242
9   QuartzCore                          0x0455c481 -[CALayer layoutSublayers] + 177
10  QuartzCore                          0x0455c1b1 CALayerLayoutIfNeeded + 220
11  QuartzCore                          0x045552e0 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 302
12  QuartzCore                          0x04555040 _ZN2CA11Transaction6commitEv + 292
13  QuartzCore                          0x04585ebb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
14  CoreFoundation                      0x0257ff4b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
15  CoreFoundation                      0x02514b27 __CFRunLoopDoObservers + 295
16  CoreFoundation                      0x024ddce7 __CFRunLoopRun + 1575
17  CoreFoundation                      0x024dd350 CFRunLoopRunSpecific + 208
18  CoreFoundation                      0x024dd271 CFRunLoopRunInMode + 97
19  GraphicsServices                    0x02d5d00c GSEventRunModal + 217
20  GraphicsServices                    0x02d5d0d1 GSEventRun + 115
21  UIKit                               0x002beaf2 UIApplicationMain + 1160
22  xwtf                                0x00001af4 main + 102
23  xwtf                                0x00001a85 start + 53
)

So it calls tableView:cellForRowAtIndexPath:on a .. String? Does anyone have any ideas?

, - UITableViewController, UITableView , doesn " . Apple iPhone, , , .

!

+3
2

, , : ViewController, NIB, DumbTableHelper. Nib http://developer.apple.com/library/mac/documentation/cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html :

nib 1, ... nib , setter ( ) . setter , , , , .

, DumbTableHelper - retainCount 1 , , . , , . , , DumbTableHelper, tableView:cellForRowAtIndexPath:.

, DumbTableHelper Interface Builder .

+4

Interface Builder . , , dataSource NSString . , datasource UITableView.

0

Source: https://habr.com/ru/post/1776101/


All Articles