Tuesday, 13 August 2013

Why is the UITableViewController numberOfRowsInSections called before the init method?

Why is the UITableViewController numberOfRowsInSections called before the
init method?

My UITableViewController won't load the information that I have downloaded
from Parse. I know that the link is working because when I ask it to print
out the PFQuery, I get the results I want. However, my problem is that the
method numberOfRowsInSection is called before the init method. I'm not
really sure how to download my data before the init method.
Here is my .m file
@implementation PicklerTable
@synthesize picklersArray;
- (id) init
{
// Call the cuperclass's designated init
self = [super initWithStyle:UITableViewStyleGrouped];
if(self){
// Insert initial data here
PFQuery *picklerQuery = [PFQuery queryWithClassName:@"Picklers"];
[picklerQuery findObjectsInBackgroundWithBlock:^(NSArray *objects,
NSError *error) {
if (!error) {
picklersArray = [[NSArray alloc] initWithArray:objects];
}
}];
}
return self;
}
-(id) initWithStyle:(UITableViewStyle)style
{
return [self init];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return picklersArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"UITableViewCell"];
PFObject *picklerObject = [picklersArray objectAtIndex:indexPath.row];
[[cell textLabel] setText:[picklerObject objectForKey:@"title"]];
return cell;
}
I put a breakpoint in the numberOfRowsInSection method and typed bt into
the console. This was my output:
thread #1: tid = 0x1c03, 0x00003430 TableControllerPractice-[PicklerTable
tableView:numberOfRowsInSection:](self=0x07c7d5a0, _cmd=0x01426163,
tableView=0x08398a00, section=0) + 64 at PicklerTable.m:50, stop reason =
breakpoint 1.1 frame #0: 0x00003430 TableControllerPractice-[PicklerTable
tableView:numberOfRowsInSection:](self=0x07c7d5a0, _cmd=0x01426163,
tableView=0x08398a00, section=0) + 64 at PicklerTable.m:50 frame #1:
0x01074548 UIKit-[UISectionRowData
refreshWithSection:tableView:tableViewRowData:] + 1822 frame #2:
0x01077224 UIKit-[UITableViewRowData numberOfRows] + 98 frame #3:
0x00f3b952 UIKit-[UITableView noteNumberOfRowsChanged] + 120 frame #4:
0x00f3b2dc UIKit-[UITableView reloadData] + 769 frame #5: 0x00f3edd6
UIKit-[UITableView _reloadDataIfNeeded] + 65 frame #6: 0x00f43a7e
UIKit-[UITableView layoutSubviews] + 36 frame #7: 0x00ee02dd
UIKit-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 279 frame #8:
0x01d366b0 libobjc.A.dylib-[NSObject performSelector:withObject:] + 70
frame #9: 0x00424fc0 QuartzCore-[CALayer layoutSublayers] + 240 frame #10:
0x0041933c QuartzCoreCA::Layer::layout_if_needed(CA::Transaction*) + 468
frame #11: 0x00424eaf QuartzCore-[CALayer layoutIfNeeded] + 166 frame #12:
0x00f7f2bd UIKit-[UIViewController window:setupWithInterfaceOrientation:]
+ 242 frame #13: 0x00ec7b56 UIKit-[UIWindow
_setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:]
+ 5346 frame #14: 0x00ec666f UIKit-[UIWindow
_setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
frame #15: 0x00ec6589 UIKit-[UIWindow
_setRotatableViewOrientation:duration:force:] + 89 frame #16: 0x00ec57e4
UIKit57-[UIWindow
_updateToInterfaceOrientation:duration:force:]_block_invoke_0 + 224 frame
#17: 0x00ec561e UIKit-[UIWindow
_updateToInterfaceOrientation:duration:force:] + 209 frame #18: 0x00ec63d9
UIKit-[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 853
frame #19: 0x00ec92d2 UIKit-[UIWindow setDelegate:] + 351 frame #20:
0x00f7399c UIKit-[UIViewController _tryBecomeRootViewControllerInWindow:]
+ 164 frame #21: 0x00ec0574 UIKit-[UIWindow
addRootViewControllerViewIfPossible] + 481 frame #22: 0x00ec076f
UIKit-[UIWindow _setHidden:forced:] + 368 frame #23: 0x00ec0905
UIKit-[UIWindow _orderFrontWithoutMakingKey] + 49 frame #24: 0x00ec9917
UIKit-[UIWindow makeKeyAndVisible] + 65 frame #25: 0x00002da6
TableControllerPractice-[HomepwnerAppDelegate
application:didFinishLaunchingWithOptions:](self=0x07c62cb0,
_cmd=0x01426c21, application=0x0b05cb60, launchOptions=0x00000000) + 742
at HomepwnerAppDelegate.m:33 frame #26: 0x00e8d157 UIKit-[UIApplication
_handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 266 frame
#27: 0x00e8d747 UIKit-[UIApplication
_callInitializationDelegatesForURL:payload:suspended:] + 1248 frame #28:
0x00e8e94b UIKit-[UIApplication
_runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] +
805 frame #29: 0x00e9fcb5 UIKit-[UIApplication handleEvent:withNewEvent:]
+ 1022 frame #30: 0x00ea0beb UIKit-[UIApplication sendEvent:] + 85 frame
#31: 0x00e92698 UIKit_UIApplicationHandleEvent + 9874 frame #32:
0x0292bdf9 GraphicsServicesPurpleEventCallback + 339 frame #33: 0x0292bad0
GraphicsServicesPurpleEventCallback + 46 frame #34: 0x01e72bf5
CoreFoundation_CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 53
frame #35: 0x01e72962 CoreFoundation__CFRunLoopDoSource1 + 146 frame #36:
0x01ea3bb6 CoreFoundation__CFRunLoopRun + 2118 frame #37: 0x01ea2f44
CoreFoundationCFRunLoopRunSpecific + 276 frame #38: 0x01ea2e1b
CoreFoundationCFRunLoopRunInMode + 123 frame #39: 0x00e8e17a
UIKit-[UIApplication _run] + 774 frame #40: 0x00e8fffc
UIKitUIApplicationMain + 1211 frame #41: 0x00002a8d
TableControllerPracticemain(argc=1, argv=0xbffff2d4) + 141 at main.m:16
frame #42: 0x000029b5 TableControllerPracticestart + 53

No comments:

Post a Comment