** -[__NSSingleObjectArrayI objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 0] - ios

I'm trying to understand the reason behind the crash.
What is __NSSingleObjectArrayI ? I couldn't find any information on this.
The crashlog sent by crashlytics is:
Fatal Exception: NSRangeException
0 CoreFoundation 0x1836fa1c0 __exceptionPreprocess
1 libobjc.A.dylib 0x18213455c objc_exception_throw
2 CoreFoundation 0x1836eb428 +[__NSSingleObjectArrayI automaticallyNotifiesObserversForKey:]
3 boostApp 0x100070098 -[LocationPromptVc tableView:didSelectRowAtIndexPath:] (LocationPromptVc.m:269)
4 UIKit 0x189683078 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
5 UIKit 0x189733b34 -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
6 UIKit 0x1897e6d5c _runAfterCACommitDeferredBlocks
7 UIKit 0x1897d8b10 _cleanUpAfterCAFlushAndRunDeferredBlocks
8 UIKit 0x189547854 _afterCACommitHandler
9 CoreFoundation 0x1836a77dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
10 CoreFoundation 0x1836a540c __CFRunLoopDoObservers
11 CoreFoundation 0x1836a589c __CFRunLoopRun
12 CoreFoundation 0x1835d4048 CFRunLoopRunSpecific
13 GraphicsServices 0x18505a198 GSEventRunModal
14 UIKit 0x1895c02fc -[UIApplication _run]
15 UIKit 0x1895bb034 UIApplicationMain
16 boostApp 0x1000bbc24 main (main.m:14)
17 libdispatch.dylib 0x1825b85b8 (Missing)
The crash is happening in the below method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//NSArray //NSArray both are strong,nonatomic
self.selectedLocation = self.filteredLocations[indexPath.row];
[self.tableView reloadData];
[self.searchField resignFirstResponder];
}
//datasource method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.filteredLocations.count;
}
74% of crashes are happening on iOS10. I have 31 crashes in the past 90 days.
Why is the didSelectRow method pointing to wrong index 18446744073709551615 ?
This crash is very rare, and I'm not able to reproduce it. Any ideas on debugging this ?
The table view is simple.IT has a search field on nav bar, and based on searchfield text,I filter locations and populate the tableview.Once the user select any row, I show the location data on different VC.

Try this code.. May this code will help. In my application I am also getting the same crash for collectionView and its very rare. Its a purely indexOutOfBounds issue. I dont know how come my collectionView showing more items than datasource count. But conditional check helps me and now my app is not crashing
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//NSArray //NSArray both are strong,nonatomic
if (self.filteredLocations.count > indexPath.row && indexPath.row >= 0) {
self.selectedLocation = self.filteredLocations[indexPath.row];
[self.tableView reloadData];
[self.searchField resignFirstResponder];
}
}

Related

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
So I have a UITableView, and the app crashes with this error every time that the array does not have any items in it. What is strange is that I have another table that does not crash when it has zero objects in the array, and I am using almost identical code for each. Here is what I have:
#implementation FindFBFriendsViewController {
NSMutableArray *friends;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UserFBFriends *fbFriends = [UserFBFriends sharedInstance];
NSLog(#"Hell0 from the fbfriends view, array is %#", fbFriends.userFriends);
friends = [[NSMutableArray alloc] initWithArray:fbFriends.userFriends];
IndFBFriend *testFriend = [friends objectAtIndex:0];
NSLog(#"USER Friends: %#", testFriend.fullName);
}
-(void)viewWillAppear:(BOOL)animated {
[self.fbTableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [friends count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FBFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:#"friendCell" forIndexPath:indexPath];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"FBFriendCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
IndFBFriend *indexRowFriend = [friends objectAtIndex:indexPath.row];
[cell updateCellWithName:indexRowFriend.fullName profilePicture:indexRowFriend.profPic personFBId:indexRowFriend.fbId];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
Here is the stack:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106213d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010597adeb objc_exception_throw + 48
2 CoreFoundation 0x00000001060f1804 -[__NSArrayM objectAtIndex:] + 212
3 gif-wrap 0x000000010338dd24 -[FindFBFriendsViewController viewDidLoad] + 340
4 UIKit 0x000000010421b984 -[UIViewController loadViewIfRequired] + 1198
5 UIKit 0x000000010422193b -[UIViewController __viewWillAppear:] + 120
6 UIKit 0x0000000104251750 -[UINavigationController _startCustomTransition:] + 1203
7 UIKit 0x0000000104261b9b -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
8 UIKit 0x0000000104262d0b -[UINavigationController __viewWillLayoutSubviews] + 57
9 UIKit 0x0000000104411503 -[UILayoutContainerView layoutSubviews] + 248
10 UIKit 0x000000010413b980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
11 QuartzCore 0x0000000109754c00 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x000000010974908e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
13 QuartzCore 0x0000000109748f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x000000010973d3c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
15 QuartzCore 0x000000010976b086 _ZN2CA11Transaction6commitEv + 486
16 UIKit 0x000000010407b72e _UIApplicationHandleEventQueue + 7135
17 CoreFoundation 0x0000000106139301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18 CoreFoundation 0x000000010612f22c __CFRunLoopDoSources0 + 556
19 CoreFoundation 0x000000010612e6e3 __CFRunLoopRun + 867
20 CoreFoundation 0x000000010612e0f8 CFRunLoopRunSpecific + 488
21 GraphicsServices 0x0000000109204ad2 GSEventRunModal + 161
22 UIKit 0x0000000104080f09 UIApplicationMain + 171
23 gif-wrap 0x00000001033922ef main + 111
24 libdyld.dylib 0x000000010752892d start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Does anybody know how I can solve this issue?
Use IndFBFriend *testFriend = [friends firstObject]; which is safer.
You say yourself that this happens when the friends array is empty. What do you expect to see when you run the following:
IndFBFriend *testFriend = [friends objectAtIndex:0];
-[NSArray objectAtIndex:] throws an exception when you access an index that does not exist; when friends is empty, that's what you see. Index 0 is invalid for an empty array.
You haven't posted your other code, but I'm guessing that your other code does not contain a line like this, so it does not crash.

Why do swipe to delete and pull to refresh cause a crash?

There's a minor bug in NSDictionary *parameters = #{#"min_id": minID};. When I swipe to delete and then pull to refresh, the app crashes.
This is the code I am using:
- (void)requestNewItemsWithCompletionHandler:
(NewItemCompletionBlock)completionHandler {
self.thereAreNoMoreOlderMessages = NO;
if (self.isRefreshing == NO) {
self.isRefreshing = YES;
// Need to add images here
NSString *minID = [[self.mediaItems firstObject] idNumber];
NSDictionary *parameters = #{#"min_id": minID};
[self populateDataWithParamaters:parameters completionHandler:^(NSError *error) {
self.isRefreshing = NO;
if (completionHandler) {
completionHandler(error);
}
}];
}
}
Here's the error message that's printed to the console:
2015-01-26 21:16:43.596 BlocstagramThird[43722:2760784] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000011087cf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000110515bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000011078861f -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 383
3 CoreFoundation 0x000000011079b64b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
4 BlocstagramThird 0x000000010ffd5012 -[DataSource requestNewItemsWithCompletionHandler:] + 322
5 BlocstagramThird 0x000000010ffda2bd -[ImagesTableViewController refreshControlDidFire:] + 173
6 UIKit 0x0000000110ead8be -[UIApplication sendAction:to:from:forEvent:] + 75
7 UIKit 0x0000000110fb4410 -[UIControl _sendActionsForEvents:withEvent:] + 467
8 UIKit 0x0000000111598a29 -[UIRefreshControl _setRefreshControlState:notify:] + 318
9 libdispatch.dylib 0x0000000112ffcba6 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x000000011301a7f4 _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000113001ede _dispatch_after_timer_callback + 334
12 libdispatch.dylib 0x000000011301a7f4 _dispatch_client_callout + 8
13 libdispatch.dylib 0x000000011301109a _dispatch_source_latch_and_call + 852
14 libdispatch.dylib 0x00000001130096d2 _dispatch_source_invoke + 412
15 libdispatch.dylib 0x0000000113003771 _dispatch_main_queue_callback_4CF + 555
16 CoreFoundation 0x00000001107e4fe9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
17 CoreFoundation 0x00000001107a7eeb __CFRunLoopRun + 2043
18 CoreFoundation 0x00000001107a7486 CFRunLoopRunSpecific + 470
19 GraphicsServices 0x0000000114d909f0 GSEventRunModal + 161
20 UIKit 0x0000000110eac420 UIApplicationMain + 1282
21 BlocstagramThird 0x000000010ffd9113 main + 115
22 libdyld.dylib 0x000000011304f145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here's the code related to swipe-to-delete:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
Media *item = [self items][indexPath.row];
[[DataSource sharedInstance] deleteMediaItem:item];
}
}
The error indicates that you were attempting to add a nil object (has to be minID based on your code sample) to a dictionary, which is not allowed.
You can validate minID before proceeding like this:
NSDictionary *parameters = nil;
if (self.mediaItems.count) {
parameters = #{#"min_id": minID};
assuming that the populateDataWithParameters method can accept a nil argument. If it can't, you need to protect around that call as well.
//add this line to viewdidload method
self.tableView.allowsMultipleSelectionDuringEditing = NO;
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
[aarname removeObjectAtIndex:indexPath.row];
[tableView reloadData];
}
}

Transition between ViewControllers is not working

I have a button in a viewcontroller which I linked with another ViewController.
On the implementation of the first viewController I created this method:
- (IBAction)SignUpPressed:(id)sender {
[self performSegueWithIdentifier:#"signup" sender:self];
}
But when I test it on the simulator, I press the button and the app crashes
argc int 1 1
argv char ** 0x7fff5fbfece8 0x00007fff5fbfece8
libc++abi.dylib: terminating with uncaught exception of type NSException
Returning this errors.
What can I do to fix this?
APPENDIX:
Code around the error (all code is above the error point)
#import "LoginViewController.h"
#import "ADVTheme.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
- (void)viewDidLoad
{
[super viewDidLoad];
id <ADVTheme> theme = [ADVThemeManager sharedTheme];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[theme viewBackground]]];
[self.loginButton setBackgroundImage:[theme colorButtonBackgroundForState:normal] forState:UIControlStateNormal] ;
[self.loginButton setBackgroundImage:[theme colorButtonBackgroundForState:UIControlStateHighlighted] forState: UIControlStateHighlighted];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.title = #"Login";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
All exception Traceback
014-02-01 11:55:05.904 theBeeGame[15793:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<LoginViewController: 0x10982c3b0>) has no segue with identifier 'signup''
*** First throw call stack:
(
0 CoreFoundation 0x0000000101f90795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101cf3991 objc_exception_throw + 43
2 UIKit 0x0000000100a43e05 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
3 theBeeGame 0x0000000100005cf1 -[LoginViewController SignUpPressed:] + 97
4 UIKit 0x0000000100957096 -[UIApplication sendAction:to:from:forEvent:] + 80
5 UIKit 0x0000000100957044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
6 UIKit 0x0000000100a2b450 -[UIControl _sendActionsForEvents:withEvent:] + 203
7 UIKit 0x0000000100a2a9c0 -[UIControl touchesEnded:withEvent:] + 530
8 UIKit 0x000000010098bc15 -[UIWindow _sendTouchesForEvent:] + 701
9 UIKit 0x000000010098c633 -[UIWindow sendEvent:] + 988
10 UIKit 0x0000000100965fa2 -[UIApplication sendEvent:] + 211
11 UIKit 0x0000000100953d7f _UIApplicationHandleEventQueue + 9549
12 CoreFoundation 0x0000000101f1fec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
13 CoreFoundation 0x0000000101f1f792 __CFRunLoopDoSources0 + 242
14 CoreFoundation 0x0000000101f3b61f __CFRunLoopRun + 767
15 CoreFoundation 0x0000000101f3af33 CFRunLoopRunSpecific + 467
16 GraphicsServices 0x000000010293c3a0 GSEventRunModal + 161
17 UIKit 0x0000000100956043 UIApplicationMain + 1010
18 theBeeGame 0x0000000100002ed3 main + 115
19 libdyld.dylib 0x00000001033295fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Please set your segue identifier "signup" on stoarybord controller.
the convention on iOS is to have method starting with lowerCase and camelCase. Make sure that your control is hooked up to the correct IBaction (case-sensitive!). Also make sure your segue identifier matches exactly (case-sensitive).
Lastly, show full exception, stack trace and the code around the location where the exception occurs (for this, set an exception breakpoint).

UiTableView - Add content to relevant sections

I'll start with saying I'm reasonably new to IOS dev!
I have an array of data which looks like this -
shopObjects *shop2 = [[shopObjects alloc]
initWithshopITitle:#"3 for 2 PT Sessions"
shopIGroup:#"standard"
shopIDesc:#"Special Offer - Get 3 bespoke PT sessions for the price of just one!" shopIPrice:#"00.20"
offer:false];
the shopIgroup field displays the section name.
I have listed the data into a tableview via the following -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// NOT SURE HOW TO CALCULATE THIS!
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// NOT SURE HOW TO CALCULATE THIS!
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =#"shopItems";
shopObjects *s = [self.shopArray objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text=s.shopITitle;
cell.textLabel.backgroundColor=[UIColor clearColor];
return cell;
}
My questions are -
How can I calculate the number of headers and the number of rows in each section required for the return statements in the above methods?
How do I then apply my cell to the relevant section?
UPDATE
My ShopObjects.m file for reference -
#implementation shopObjects
-(id)initWithshopITitle:(NSString *)shopITitleD shopIGroup:(NSString *)shopIGroupD shopIDesc:(NSString *)shopIDescD shopIPrice:(NSString *)shopIPriceD offer:(Boolean )offerD{
self= [super init];
if(self){
self.shopITitle = shopITitleD;
self.shopIGroup = shopIGroupD;
self.shopIDesc = shopIDescD;
self.shopIPrice = shopIPriceD;
self.offer = (offerD);
}
return self;
}
ShopObjects.h file
import
#interface shopObjects : NSObject
#property(strong) NSString *shopITitle;
#property(strong) NSString *shopIGroup;
#property(strong) NSString *shopIDesc;
#property(strong) NSString *shopIPrice;
#property Boolean offer;
-(id)initWithshopITitle:(NSString *)shopITitleD shopIGroup:(NSString *)shopIGroupD shopIDesc:(NSString *)shopIDescD shopIPrice:(NSString *)shopIPriceD offer:(BOOL )offerD;
#end
array setup
shopObjects *shop1 = [[shopObjects alloc] initWithshopITitle:#"1 x PT Session" shopIGroup:#"running" shopIDesc:#"1 x 1hour fitness session with Zoe - bespoke fitness session.\n\nZoe's sessions focus on your general health and fitness so she will look at a bespoke fitness schedule that encompasses exersize, healthy eating, sleep and general lifestyle - to help you meet your goals.\n\nBe good to yourslef and give it a go.." shopIPrice:#"10.00" offer:false];
shopObjects *shop2 = [[shopObjects alloc] initWithshopITitle:#"3 for 2 PT Sessions" shopIGroup:#"offers" shopIDesc:#"Special Offer - Get 3 bespoke PT sessions for the price of just one!" shopIPrice:#"00.20" offer:false];
shopObjects *shop3 = [[shopObjects alloc] initWithshopITitle:#"1 x Running Club" shopIGroup:#"running" shopIDesc:#"1 x running club session - roup event - max group of 10." shopIPrice:#"15.00" offer:false];
shopObjects *shop4 = [[shopObjects alloc] initWithshopITitle:#"1 x Weights session" shopIGroup:#"weights" shopIDesc:#"1 x body building sesson" shopIPrice:#"10.90" offer:false];
self.shopArray = [NSArray arrayWithObjects:shop1, shop2, shop3,shop4, nil];
self.sectionData = [self.shopArray valueForKeyPath:#"#distinctUnionOfObjects.shopIGroup"];
UPDATE
For Greg - I have implemented your code and suggestions and app still crashes, I now get -
NSLOG -
2013-12-05 10:16:18.595 blah[3321:70b] Value of hello = 0
2013-12-05 10:16:18.596 blah[3321:70b] Value of hello = 1
2013-12-05 10:16:18.596 blah[3321:70b] Value of hello = 2
2013-12-05 10:16:27.962 blah[3321:70b] SECTIONS: 3
2013-12-05 10:16:27.962 blah[3321:70b] -[NSCFConstantString shopIGroup]: unrecognized selector sent to instance 0x1c7c38
2013-12-05 10:16:27.965 blah[3321:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString shopIGroup]: unrecognized selector sent to instance 0x1c7c38'
*** First throw call stack:
(
0 CoreFoundation 0x02bde5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x029618b6 objc_exception_throw + 44
2 CoreFoundation 0x02c7b903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x02bce90b ___forwarding_ + 1019
4 CoreFoundation 0x02bce4ee _CF_forwarding_prep_0 + 14
5 blah 0x000198fb -[shopTVcontroller tableView:numberOfRowsInSection:] + 187
6 UIKit 0x00a33dc0 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2510
7 UIKit 0x00a39384 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 288
8 UIKit 0x00a39495 -[UITableViewRowData heightForTable] + 68
9 UIKit 0x008ae181 -[UITableView _updateContentSize] + 400
10 UIKit 0x008c9333 -[UITableView setContentInset:] + 329
11 UIKit 0x008efeba -[UIViewController _setNavigationControllerContentInsetAdjustment:] + 538
12 UIKit 0x0091a9bc -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 399
13 UIKit 0x0091ab2e -[UINavigationController _layoutViewController:] + 64
14 UIKit 0x0091b02b -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
15 UIKit 0x0090f8ff -[UINavigationController _startCustomTransition:] + 2087
16 UIKit 0x0091c0c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
17 UIKit 0x0091ccb9 -[UINavigationController viewWillLayoutSubviews] + 57
18 UIKit 0x00a56181 -[UILayoutContainerView layoutSubviews] + 213
19 UIKit 0x0084c267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
20 libobjc.A.dylib 0x0297381f -[NSObject performSelector:withObject:] + 70
21 QuartzCore 0x0221a2ea -[CALayer layoutSublayers] + 148
22 QuartzCore 0x0220e0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
23 QuartzCore 0x0220df40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
24 QuartzCore 0x02175ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
25 QuartzCore 0x02176e71 _ZN2CA11Transaction6commitEv + 393
26 QuartzCore 0x02177544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
27 CoreFoundation 0x02ba64ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30
28 CoreFoundation 0x02ba641f __CFRunLoopDoObservers + 399
29 CoreFoundation 0x02b84344 __CFRunLoopRun + 1076
30 CoreFoundation 0x02b83ac3 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x02b838db CFRunLoopRunInMode + 123
32 GraphicsServices 0x03c349e2 GSEventRunModal + 192
33 GraphicsServices 0x03c34809 GSEventRun + 104
34 UIKit 0x007e1d3b UIApplicationMain + 1225
36 libdyld.dylib 0x0314f70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Error screen -
You can get section by get distinct sections of your objects from array. The best way is to add new #property of NSArray type (you will need it later) for example sectionData and in viewDidLoad load it with distinct values:
self.sectionData = [self.shopArray valueForKeyPath:#"#distinctUnionOfObjects.shopIGroup"];
Next you can just display a number of distinct object which gives you number of sections
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.sectionData count];
}
To get number of rows per section you have to filter the array for section name like that:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//Get your section name from distinct array
NSString *s = self.sectionData[section]
//Filter your main array
NSPredicate *pred = [NSPredicate predicateWithFormat:#"shopIGroup like %#", s];
NSArray *filteredArr = [self.shopArray filteredArrayUsingPredicate:pred];
return [filteredArr count];
}
To display the data you have to do something similar as above in cellForRowAtIndexPathMethod:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =#"shopItems";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//Get your section name from distinct array
NSString *s = self.sectionData[indexPath.section]
//Filter your main array
NSPredicate *pred = [NSPredicate predicateWithFormat:#"shopIGroup like %#", s];
NSArray *filteredArr = [self.shopArray filteredArrayUsingPredicate:pred];
shopObjects *rightS = filteredArr[indexPath.row]
cell.textLabel.text=rightS.shopITitle;
cell.textLabel.backgroundColor=[UIColor clearColor];
return cell;
}
I would recommended you to change data structure. In this kind of project I use array(mainArray) with another array embedded (sectionArray) where I keep object. So I know that for example my first array contain another array of object for first section.
And I can yes section like that:
[mainArray count]
And rows per section like that:
mainArray[section].count
And data for each row:
mainArray[section][row]
Hope you find it useful.
You can use TLIndexPathDataModel from TLIndexPathTools instead of an array. It can organize your data into sections and provide a bunch of handy APIs for implementing your data source and delegate methods like [dataModel numberOfRowsInSection:] and [dataModel itemForRowAtIndexPath:].
In your case, you'd create your data model like this:
NAArray *items = ...;// array of shopObjects
TLIndexPathDataModel *dataModel = [[TLIndexPathDataModel alloc] initWithItems:items sectionNameKeyPath:#"shopIGroup" identifierKeyPath:nil];

PresentViewController crash on iOS 6

i got a weird crash problem of my App. Once I enter B ViewController from A ViewController, it crash(not every time, only happened once). here is the code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSUInteger section = [indexPath section];
if( section == 0 && row == 0 && self.uidString && self.profileDic)
{
BViewController *bviewcontroller = [[BViewController alloc] init];
[bviewcontroller setProfileDic:self.profileDic];
bviewcontroller.delegate = self;
bviewcontroller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:bviewcontroller animated:YES];
[bviewcontroller release];
}
}
and the crash log is
Date/Time: 2013-06-18 10:00:39.720 +0800
OS Version: iOS 6.1.4 (10B350)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x31d3c3e2 __exceptionPreprocess + 158
1 libobjc.A.dylib 0x39a3795e objc_exception_throw + 26
2 CoreFoundation 0x31d3c298 +[NSException raise:format:arguments:] + 96
3 Foundation 0x32612f9e -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 86
4 UIKit 0x33c37754 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 172
5 UIKit 0x33c36fa6 -[UIViewController presentViewController:withTransition:completion:] + 3394
6 UIKit 0x33d58d9e -[UIViewController presentModalViewController:animated:] + 26
I looked for answers and some posts here said it is because "presentViewController" method of UIViewController is not available on iOS 4.3 and the solution is just to change "presentViewController" to "presentModalViewController". But that is exactly what my code did. So is there anyone who know what might happen? Thanks in advance.
You might need to retain your presented view controller somewhere (e.g. in an iVar). I am guessing it is getting deallocated before it shows up.

Resources