I've been working on this for a few days. Any idea what this means? please help!
let me know if more info is required
EXC_BAD_ACCESS (SIGSEGV)
Thread 11 name: Dispatch queue: com.apple.CoreLocation.ConnectionClient.0x200826b0.events
Thread 11 Crashed:
0 libdispatch.dylib 0x387b2420 dispatch_sync_f$VARIANT$mp + 0
1 CoreLocation 0x393c8088 CLConnectionClient::setCachedResponse(CLConnectionMessage*, bool ( block_pointer)()) + 76
2 CoreLocation 0x393c8558 __setDefaultMessageHandler_onQueue_block_invoke_0 + 28
3 CoreLocation 0x393c7070 __setEventHandler_block_invoke_0 + 344
4 libxpc.dylib 0x367ef7e4 _xpc_connection_mach_event + 768
5 libdispatch.dylib 0x387b6524 _dispatch_mach_msg_invoke$VARIANT$mp + 120
6 libdispatch.dylib 0x387b2e8e _dispatch_queue_drain$VARIANT$mp + 78
7 libdispatch.dylib 0x387b67b2 _dispatch_mach_invoke$VARIANT$mp + 158
8 libdispatch.dylib 0x387b2e8e _dispatch_queue_drain$VARIANT$mp + 78
9 libdispatch.dylib 0x387b2dbc _dispatch_queue_invoke$VARIANT$mp + 36
10 libdispatch.dylib 0x387b2e8e _dispatch_queue_drain$VARIANT$mp + 78
11 libdispatch.dylib 0x387b2dbc _dispatch_queue_invoke$VARIANT$mp + 36
12 libdispatch.dylib 0x387b391a _dispatch_root_queue_drain + 182
13 libdispatch.dylib 0x387b3abc _dispatch_worker_thread2 + 80
14 libsystem_c.dylib 0x34097a0e _pthread_wqthread + 358
15 libsystem_c.dylib 0x340978a0 start_wqthread + 4
- (void)startupLocationManager
{
// startup location manager for background processing
if (self.locationManager == nil)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
}
- (void)stopLocationManager
{
if (self.locationManager)
{
[self.locationManager stopUpdatingLocation];
self.locationManager.delegate = nil;
self.locationManager = nil;
if (self.isInBackground == YES)
{
[self startupLocationManager];
}
}
}
I found a solution with help from other posts. It turned out to be a timing issue. I created another method to reset my location manager and I call it with a delay. This fixed everything. Hope this helps you too.
- (void)stopLocationManager
{
if (locationManager)
{
[locationManager stopUpdatingLocation];
[self performSelector:#selector(discardLocationManager) withObject:nil afterDelay:0.1];
}
}
- (void) discardLocationManager
{
locationManager.delegate = nil;
locationManager = nil;
if (self.isRestart == YES)
{
[self performSelector:#selector(startupLocationManager) withObject:nil afterDelay:0.1];
}
}
Related
I am trying to populate a table view with the file names of the files located in the documents directory but when the button is clicked to show the table view the app crashes saying that the object at index is 0. but there are 14 objects in the array. What could be the fault?
#implementation loadDataTVC
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void) viewWillAppear:(BOOL)animated{
DataSource *sharedManager = [DataSource sharedManager];
NSString *documentDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
sharedManager.directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentDirectoryPath error:NULL];
NSLog(#"%lu", (unsigned long)[sharedManager.directoryContent count]);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
DataSource *sharedManager = [DataSource sharedManager];
NSString *documentDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
sharedManager.directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentDirectoryPath error:NULL];
if (sharedManager.directoryContent.count > 0) {
return (unsigned long)[sharedManager.directoryContent count];
}
else{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"files" forIndexPath:indexPath];
DataSource *sharedManager = [DataSource sharedManager];
NSString *documentDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
sharedManager.directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentDirectoryPath error:NULL];
if (sharedManager.directoryContent.count > 0) {
cell.textLabel.text = [NSString stringWithFormat:#"%#", [sharedManager.directoryContent objectAtIndex:indexPath.row]];
}
else{
cell.textLabel.text = #"No data Available";
}
return cell;
}
The log:
2016-05-18 15:00:44.502 GeoData Grapher[4554:331076] 14
2016-05-18 15:00:47.412 GeoData Grapher[4554:331076] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d2cdd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010cd41deb objc_exception_throw + 48
2 CoreFoundation 0x000000010d275885 -[__NSArray0 objectAtIndex:] + 101
3 GeoData Grapher 0x000000010a5f07d6 -[DeviceListTVC prepareForSegue:sender:] + 326
4 UIKit 0x000000010bcc95d5 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 369
5 UIKit 0x000000010bcc9433 -[UIStoryboardSegueTemplate _perform:] + 82
6 UIKit 0x000000010bcc96f7 -[UIStoryboardSegueTemplate perform:] + 156
7 UIKit 0x000000010b583a8d -[UIApplication sendAction:to:from:forEvent:] + 92
8 UIKit 0x000000010b991067 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 152
9 UIKit 0x000000010b583a8d -[UIApplication sendAction:to:from:forEvent:] + 92
10 UIKit 0x000000010b6f6e67 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x000000010b6f7143 -[UIControl _sendActionsForEvents:withEvent:] + 327
12 UIKit 0x000000010b6f72be -[UIControl _sendActionsForEvents:withEvent:] + 706
13 UIKit 0x000000010b6f6263 -[UIControl touchesEnded:withEvent:] + 601
14 UIKit 0x000000010b5f699f -[UIWindow _sendTouchesForEvent:] + 835
15 UIKit 0x000000010b5f76d4 -[UIWindow sendEvent:] + 865
16 UIKit 0x000000010b5a2dc6 -[UIApplication sendEvent:] + 263
17 UIKit 0x000000010b57c553 _UIApplicationHandleEventQueue + 6660
18 CoreFoundation 0x000000010d1f3301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x000000010d1e922c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x000000010d1e86e3 __CFRunLoopRun + 867
21 CoreFoundation 0x000000010d1e80f8 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x000000010eb7aad2 GSEventRunModal + 161
23 UIKit 0x000000010b581f09 UIApplicationMain + 171
24 GeoData Grapher 0x000000010a5f405f main + 111
25 libdyld.dylib 0x000000011253c92d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The Segue:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *selectedPath = [self.tableView indexPathForCell:sender];
AirconsoleDevice *selectedDevice = self.manager.defaultDevice;
if (selectedPath.section == 0) {
selectedDevice = self.currentDevices[selectedPath.row];
}
if ([segue.identifier isEqualToString:#"session_details"]) {
AirconsoleSession *session = [[AirconsoleSession alloc] initWithDevice:selectedDevice];
currentSession = session;
SessionDetailsVC *sdvc = segue.destinationViewController;
sdvc.session = session;
} else {
// we are presenting the Device Details
DeviceDetailsTVC *ddvc = [segue.destinationViewController viewControllers][0];
ddvc.device = selectedDevice;
}
}
The problem is in this line
DeviceDetailsTVC *ddvc = [segue.destinationViewController viewControllers][0];
ddvc.device = selectedDevice;
The destination controller is I assume a Navigation controller. And you are accessing the first controller in the stack.
Check this is actually set up correctly in the Storyboard. Because thats what the line of code expects, but the crash says it cannot find any member in the viewControllers array.
AFAIK it has nothing to do with the table view and 14 items.
I'm using the UNIRest library and I'm trying to switch to another ViewController on the response of an HTTP GET method.
[[UNIRest get:^(UNISimpleRequest *request) {
[request setUrl:GEtFamilyMembers];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
NSLog(#"res: %#", response.body);
if (response.code == 200) {
GCHFamilyMembersViewConroller* fmViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"gchFamilyMembers"];
self.navigationController.viewControllers = #[fmViewController];
[self.mm_drawerController setCenterViewController:self.navigationController withCloseAnimation:YES completion:nil];
} else {
[self showToast:#"Something went wrong, Please try again after some time."];
}
}];
Even after printing the response using NSLog. Nothing happens for about 30 seconds. Then suddenly app crashes.
I thought it's because Asynch call blocks UI so I tired a method like:
- (void) gotoSelectFamilyMembers {
dispatch_async(dispatch_get_main_queue(), ^{
GCHFamilyMembersViewConroller* fmViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"gchFamilyMembers"];
self.navigationController.viewControllers = #[fmViewController];
[self.mm_drawerController setCenterViewController:self.navigationController withCloseAnimation:YES completion:nil];
});
}
but still the app crashes.
Earlier when I was using a Synchronous call it was working. But not now.
Please help!
EDIT:
2016-05-02 17:58:22.695 Checkme Mobile[6208:136321] *** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /SourceCache/UIKit_Sim/UIKit-3347.44.2/Keyboard/UIKeyboardTaskQueue.m:374
2016-05-02 17:58:22.728 Checkme Mobile[6208:136224] NSScanner: nil string argument
2016-05-02 17:58:22.728 Checkme Mobile[6208:136224] NSScanner: nil string argument
2016-05-02 17:58:23.730 Checkme Mobile[6208:136224] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001094a6c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108da2bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001094a6aca +[NSException raise:format:arguments:] + 106
3 Foundation 0x00000001089b798f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000107d887d6 -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 151
5 UIKit 0x0000000107829912 -[UIKeyboardImpl setDelegate:force:] + 473
6 UIKit 0x0000000107ad44ad -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1002
7 UIKit 0x0000000107adc834 -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 504
8 UIKit 0x000000010778e181 -[UINavigationController navigationTransitionView:didStartTransition:] + 578
9 UIKit 0x00000001079948bc -[UINavigationTransitionView transition:fromView:toView:] + 655
10 UIKit 0x0000000107792170 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2984
11 UIKit 0x0000000107792408 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523
12 UIKit 0x0000000107792ece -[UINavigationController __viewWillLayoutSubviews] + 43
13 UIKit 0x00000001078dd6d5 -[UILayoutContainerView layoutSubviews] + 202
14 UIKit 0x00000001076b09eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
15 QuartzCore 0x0000000109d83ed2 -[CALayer layoutSublayers] + 146
16 QuartzCore 0x0000000109d786e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x0000000109d78556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
18 QuartzCore 0x0000000109ce486e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
19 QuartzCore 0x0000000109ce5a22 _ZN2CA11Transaction6commitEv + 462
20 QuartzCore 0x0000000109ce5c99 _ZN2CA11Transaction14release_threadEPv + 199
21 libsystem_pthread.dylib 0x000000010a35172a _pthread_tsd_cleanup + 86
22 libsystem_pthread.dylib 0x000000010a351451 _pthread_exit + 117
23 libsystem_pthread.dylib 0x000000010a3506cd _pthread_wqthread + 879
24 libsystem_pthread.dylib 0x000000010a34e40d start_wqthread + 13
)
2016-05-02 17:58:23.730 Checkme Mobile[6208:136321] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001094a6c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108da2bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001094a6aca +[NSException raise:format:arguments:] + 106
3 Foundation 0x00000001089b798f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000107d887d6 -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 151
5 UIKit 0x0000000107829912 -[UIKeyboardImpl setDelegate:force:] + 473
6 UIKit 0x0000000107ad44ad -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1002
libc++abi.dylib: 7 UIKit 0x0000000107adc834 -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 504
8 UIKit 0x000000010778e181 -[UINavigationController navigationTransitionView:didStartTransition:] + 578
9 UIKit 0x00000001079948bc -[UINavigationTransitionView transition:fromView:toView:] + 655
10 UIKit 0x0000000107792170 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2984
11 UIKit 0x0000000107792408 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523
12 UIKit 0x0000000107792ece -[UINavigationController __viewWillLayoutSubviews] + 43
13 UIKit 0x00000001078dd6d5 -[UILayoutContainerView layoutSubviews] + 202
14 UIKit 0x00000001076b09eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
15 QuartzCore 0x0000000109d83ed2 -[CALayer layoutSublayers] + 146
16 QuartzCore 0x0000000109d786e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x0000000109d78556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
18 QuartzCore 0x0000000109ce486e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
19 QuartzCore 0x0000000109ce5a22 _ZN2CA11Transaction6commitEv + 462
20 QuartzCore 0x0000000109ce5c99 _ZN2CA11Transaction14release_threadEPv + 199
21 libsystem_pthread.dylib 0x000000010a35172a _pthread_tsd_cleanup + 86
22 libsystem_pthread.dylib 0x000000010a351451 _pthread_exit + 117
23 libsystem_pthread.dylib 0x000000010a3506cd _pthread_wqthread + 879
24 libsystem_pthread.dylib 0x000000010a34e40d start_wqthread + 13
)
terminating with uncaught exception of type NSExceptionlibc++abi.dylib:
terminating with uncaught exception of type NSException
(lldb)
EDit:
- (IBAction)loginAction:(id)sender {
self.email = usernameTextField.text;
self.password = passwordTextField.text;
if(!([self.email isEqualToString:#""] && [self.password isEqualToString:#""])) {
[self performLogin];
} else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"error" message:#"Enter both username and password." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
- (void) performLogin {
NSDictionary* headers = #{#"Content-Type": #"application/x-www-form-urlencoded"};
NSDictionary* parameters = #{#"username": self.email, #"password": self.password};
[[NSThread currentThread] isMainThread] ? NSLog(#"1MAIN THREAD") : NSLog(#"1NOT MAIN THREAD");
self.loginConnection = [[UNIRest post:^(UNISimpleRequest *request) {
[request setUrl:LOgin];
[request setHeaders:headers];
[request setParameters:parameters];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
// This is the asyncronous callback block
[[NSThread currentThread] isMainThread] ? NSLog(#"2MAIN THREAD") : NSLog(#"2NOT MAIN THREAD");
UNIJsonNode *body = response.body;
NSData *rawBody = response.rawBody;
NSString *string = [[NSString alloc] initWithData:rawBody encoding:NSUTF8StringEncoding];
NSLog(#"response signup: %#", string);
if (response.code == 200) {
[self processLoginResponse:body];
}
}];
}
- (void) processLoginResponse:(UNIJsonNode *) body {
if ([body.JSONObject[#"status"] boolValue] == YES) {
NSString *firstName = body.JSONObject[#"firstName"];
NSString *lastName = body.JSONObject[#"lastName"];
NSString *name = [firstName stringByAppendingString:lastName];
NSMutableDictionary *mDictionary = [[NSMutableDictionary alloc] init];
[mDictionary setObject:body.JSONObject[#"accountId"] forKey:#"accountId"];
[mDictionary setObject:name forKey:#"name"];
[mDictionary setObject:#"Custodian" forKey:#"relation"];
[self fetchFamilyMembers:mDictionary];
} else {
[self showAlert:body.JSONObject[#"message"]];
}
}
- (void) fetchFamilyMembers:(NSMutableDictionary *) mDictionary {
[[NSThread currentThread] isMainThread] ? NSLog(#"3MAIN THREAD") : NSLog(#"3NOT MAIN THREAD");
self.fmConnection = [[UNIRest get:^(UNISimpleRequest *request) {
[request setUrl:GEtFamilyMembers];
}] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
NSLog(#"res: %#", response.body);
if (response.code == 200) {
[[NSThread currentThread] isMainThread] ? NSLog(#"4MAIN THREAD") : NSLog(#"4NOT MAIN THREAD");
NSData *rawBody = response.rawBody;
NSString *string = [[NSString alloc] initWithData:rawBody encoding:NSUTF8StringEncoding];
NSLog(#"family signup: %#", string);
[[NSThread currentThread] isMainThread] ? NSLog(#"5MAIN THREAD") : NSLog(#"5NOT MAIN THREAD");
[self processFamilyMembersResponse:mDictionary :response.body];
} else {
[self showToast:#"Something went wrong, Please try again after some time."];
}
}];
}
- (void) processFamilyMembersResponse:(NSMutableDictionary *) mDictionary :(UNIJsonNode *) body {
NSArray *fmArray = body.JSONArray;
if (fmArray == nil || [fmArray count] == 0) {
NSNumber *accountId = (NSNumber *)[mDictionary objectForKey:#"accountId"];
} else {
NSMutableArray *mArray = [[NSMutableArray alloc] init];
[mArray addObject:mDictionary];
for (int i = 0; i < fmArray.count; i++) {
NSDictionary *fmDictionary = [fmArray objectAtIndex:i];
mDictionary = [[NSMutableDictionary alloc] init];
NSNumber *accountId = (NSNumber *)[fmDictionary objectForKey:#"id"];
[mDictionary setObject:accountId forKey:#"accountId"];
[mDictionary setObject:[fmDictionary objectForKey:#"name"] forKey:#"name"];
[mDictionary setObject:[fmDictionary objectForKey:#"relation"] forKey:#"relation"];
[mArray addObject:mDictionary];
}
[[NSThread currentThread] isMainThread] ? NSLog(#"6MAIN THREAD") : NSLog(#"6NOT MAIN THREAD");
[self gotoSelectFamilyMembers:mArray];
}
}
- (void) gotoSelectFamilyMembers:(NSMutableArray *) mArray {
dispatch_async(dispatch_get_main_queue(), ^{
GCHFamilyMembersViewConroller* fmViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"gchFamilyMembers"];
fmViewController._tblData = mArray;
self.navigationController.viewControllers = #[fmViewController];
[self.mm_drawerController setCenterViewController:self.navigationController withCloseAnimation:YES completion:nil];
});
}
Try below code:
dispatch_async(dispatch_get_main_queue(), ^{
GCHFamilyMembersViewConroller* fmViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"gchFamilyMembers"];
fmViewController._tblData = mArray;
((AppDelegate*)[[UIApplication sharedApplication]delegate]).navigationController.viewControllers = #[fmViewController];
[self.mm_drawerController setCenterViewController:((AppDelegate*)[[UIApplication sharedApplication]delegate]).navigationController withCloseAnimation:YES completion:nil];
});
You're using the asynchronous calls of Unirest and the response should be called on the UI thread (Main thread). Usually libraries similar to this deliver the result on the main thread. Therefore, I think you do not need to specifically call dispatch_async on the main queue. However, you can use the following check to see whether it gets called on the main thread or not.
[[NSThread currentThread] isMainThread] ? NSLog(#"MAIN THREAD") : NSLog(#"NOT MAIN THREAD");
Here's what I suspect
Your ViewController creation method has some fault and is consuming time
Your response is very large
I suggest that you call the following without any web service calls to confirm that they do not cause the crash.
GCHFamilyMembersViewConroller* fmViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"gchFamilyMembers"];
self.navigationController.viewControllers = #[fmViewController];
[self.mm_drawerController setCenterViewController:self.navigationController withCloseAnimation:YES completion:nil];
I have MBProgressHUD implemented into my objective-c project and while the progressHUD starts my app crashes. Here is my log
0 CoreFoundation 0x0000000102b35f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101b08deb objc_exception_throw + 48
2 CoreFoundation 0x0000000102b3e56d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000102a8beea ___forwarding___ + 970
4 CoreFoundation 0x0000000102a8ba98 _CF_forwarding_prep_0 + 120
5 EyeQueExam 0x0000000100e80762 -[MBProgressHUD launchExecution] + 82
6 Foundation 0x0000000101792eab __NSThread__start__ + 1198
7 libsystem_pthread.dylib 0x000000010568e05a _pthread_body + 131
8 libsystem_pthread.dylib 0x000000010568dfd7 _pthread_body + 0
9 libsystem_pthread.dylib 0x000000010568b3ed thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Also this line of code gets a signal SIGABRT error:
[targetForExecution performSelector:methodForExecution withObject:objectForExecution];
Edit:
// MBProgressHUD
HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.labelText = #"Uploading to Cloud...";
HUD.detailsLabelText = #"Just relax";
HUD.mode = MBProgressHUDModeAnnularDeterminate;
[self.view addSubview:HUD];
[HUD show:YES];
[HUD showWhileExecuting:#selector(load) onTarget:self withObject:nil animated:YES];
-(NSArray*) load: (NSString *) componentName
{
float progress = 0.0;
while (progress < 1.0) {
progress += 0.01;
HUD.progress = progress;
usleep(50000);
}
}
Try edit this code:
[HUD showWhileExecuting:#selector(load) onTarget:self withObject:nil animated:YES];
To:
[HUD showWhileExecuting:#selector(load:) onTarget:self withObject:nil animated:YES];
Transform load method in (void)
- (void) load {
}
Your code:
- (void) load {
{
float progress = 0.0;
while (progress < 1.0) {
progress += 0.01;
HUD.progress = progress;
usleep(50000);
}
}
I am not able to figure out what is causing the application crash. A UITableView is being filled with data using the method numberOfRowsInSection. The first two record loads correctly but when the 3rd row is about to load, the app crashes. Please help.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myDictionary = self.myArray;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myDictionary count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"TransHistoryCell";
TransHistoryCell *cell = (TransHistoryCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
#try
{
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"TransHistoryCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary *currentDictionary = [myDictionary objectAtIndex:indexPath.row];
for(NSDictionary *object in currentDictionary)
{
NSString *key = [object valueForKey:#"Key"];
NSString *value = [object valueForKey:#"Value"];
if([key isEqualToString:DATE])
{
cell.dateLabel.text = value;
}
else if([key isEqualToString:TRANSACTION_ID])
{
cell.transactionIdLabel.text = value;
}
else if([key isEqualToString:THIRD_PARTY])
{
cell.thirdPartyLabel.text = value;
}
else if([key isEqualToString:AMOUNT])
{
cell.amountLabel.text = value;
}
else if([key isEqualToString:TRANSACTION_DESC])
{
cell.transactionDescLabel.text = value;
}
}
}
#catch (NSException *exception)
{
NSLog(#"Exception: %#", exception);
}
#finally
{
return cell;
}
}
Exception:
2015-01-14 09:49:12.808 MobileProject[19580:5974561] -[NSNull length]: unrecognized selector sent to instance 0x103796ce0
2015-01-14 09:49:12.812 MobileProject
[19580:5974561] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x103796ce0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001034edf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102187bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001034f504d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010344d27c ___forwarding___ + 988
4 CoreFoundation 0x000000010344ce18 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001009b2f45 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 65
6 UIKit 0x00000001009b2da0 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 76
7 UIKit 0x00000001009b6852 -[UILabel _intrinsicSizeWithinSize:] + 170
8 UIKit 0x00000001009b6932 -[UILabel intrinsicContentSize] + 76
9 UIKit 0x0000000100e6cea4 -[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 33
10 UIKit 0x0000000100e6cc64 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 422
11 UIKit 0x0000000100e740d6 -[UIView(AdditionalLayoutSupport) updateConstraints] + 163
12 UIKit 0x00000001009b679d -[UILabel updateConstraints] + 272
13 UIKit 0x0000000100e736fa -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 248
14 UIKit 0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
15 CoreFoundation 0x00000001033f6194 CFArrayApplyFunction + 68
16 UIKit 0x0000000100e7369b -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
17 Foundation 0x0000000101aead6e -[NSISEngine withBehaviors:performModifications:] + 155
18 UIKit 0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
19 CoreFoundation 0x00000001033f6194 CFArrayApplyFunction + 68
20 UIKit 0x0000000100e7369b -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
21 UIKit 0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
22 UIKit 0x0000000100e73dbe __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 96
23 UIKit 0x0000000100e73a86 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 231
24 UIKit 0x0000000100c698b8 -[UITableViewCellContentView updateConstraintsIfNeeded] + 95
25 UIKit 0x0000000100e7419e -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 159
26 UIKit 0x000000010085ab2d -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 114
27 UIKit 0x0000000100866973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
28 QuartzCore 0x0000000103d6ade8 -[CALayer layoutSublayers] + 150
29 QuartzCore 0x0000000103d5fa0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
30 QuartzCore 0x0000000103d5f87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
31 QuartzCore 0x0000000103ccd63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
32 QuartzCore 0x0000000103cce74a _ZN2CA11Transaction6commitEv + 390
33 QuartzCore 0x0000000103ccedb5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
34 CoreFoundation 0x0000000103422dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
35 CoreFoundation 0x0000000103422d20 __CFRunLoopDoObservers + 368
36 CoreFoundation 0x0000000103418b53 __CFRunLoopRun + 1123
37 CoreFoundation 0x0000000103418486 CFRunLoopRunSpecific + 470
38 GraphicsServices 0x000000010338b9f0 GSEventRunModal + 161
39 UIKit 0x00000001007ed420 UIApplicationMain + 1282
40 MobileProject 0x0000000100535c83 main + 115
41 libdyld.dylib 0x0000000107323145 start + 1
42 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
you are trying to get the length of what you think is an NSString but is actually NSNull. so check the NSNULL value in both key's ` Key and value
each time i try and click on the search bar, the app keeps crashing, below is the code for the UItableview used with the parse.com SDK, is there something i missed on the code. its crashing when the search bar is clicked, before the keyboard gets loaded.
#
NSRangeException', reason: ' -[NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' ** First throw call stack: ( 0 CoreFoundation 0x0000000102cb1795 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000102a14991 objc_exception_throw + 43 2 CoreFoundation
#
this is the view did load method to load search bar
#interface CarTableViewController () <UISearchDisplayDelegate, UISearchBarDelegate>
{
GADBannerView *bannerView_;
}
# property (nonatomic, strong) UISearchBar * searchbar;
# property (nonatomic, strong) UISearchDisplayController *searchcontroller;
# property (nonatomic, strong) NSMutableArray * SearchResults;
#end
#implementation CarTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//search bar
self.searchbar = [[UISearchBar alloc] initWithFrame: CGRectMake (0, 0, self.view.frame.size.width, 44)];
self.tableView.tableHeaderView = self.searchbar;
self.searchcontroller = [[UISearchDisplayController alloc] initWithSearchBar: self.searchbar contentsController: self];
self.searchcontroller.searchResultsDataSource = self;
self.searchcontroller.searchResultsDelegate = self;
self.searchcontroller.delegate = self;
CGPoint offset = CGPointMake(0, self.searchbar.frame.size.height);
self.tableView.contentOffset = offset;
self.searchResults = [NSMutableArray array];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
this is the load for parse
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
self.parseClassName = #"movienow";
self.textKey = #"mName";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = NO;
}
return self;
}
//where to search and other
- (void) filterResults: (NSString *)searchTerm{
[self.SearchResults removeAllObjects];
PFQuery * query = [PFQuery queryWithClassName: self.parseClassName]; // table in which you are looking for
[query whereKeyExists: # "mName"]; // column which you are looking for
[query whereKey: # "mName" containsString : searchTerm];
NSArray * results = [query findObjects];
[self.SearchResults addObjectsFromArray: results];
}
- (BOOL) searchDisplayController:(UISearchDisplayController *) controller shouldReloadTableForSearchString: (NSString *) searchstring {
[self filterResults: searchstring];
return YES;
}
- (NSInteger) Tableview: (UITableView *) Tableview numberOfRowsInSection: (NSInteger) section {
if (Tableview == self.tableView) {
return self.objects.count;
} else {
return self.SearchResults.count;
}
}
- (void) callbackLoadObjectsFromParse: (NSArray *)result error:(NSError *) error {
if (!error) {
[self.SearchResults removeAllObjects],
[self.SearchResults addObjectsFromArray: result];
[self.searchDisplayController.searchResultsTableView reloadData];
} else {
NSLog (# "Error:%# %#", error, [error userInfo]);
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *CellIdentifier = #"CarTableCell";
CarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (tableView == self.tableView) {
//cell.mName.text = [object objectForKey:#"objectld"];
NSLog(#"%#",[object objectForKey:#"mName"]);
}
else if (tableView == self.searchDisplayController.searchResultsTableView){
PFObject *searchUser = [self.SearchResults objectAtIndex:indexPath.row];
NSLog(#"%#",[searchUser objectForKey:#"mName"]);
}
// Configure the cell...
return cell;
}
crash log
2014-01-23 15:58:23.440 MovieTimeLK2[8442:70b] * Terminating app due to uncaught exception 'NSRangeException', reason: ' -[NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
** First throw call stack:
(
0 CoreFoundation 0x0000000102cb1795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102a14991 objc_exception_throw + 43
2 CoreFoundation 0x0000000102c578e5 -[__NSArrayM objectAtIndex:] + 213
3 MovieTimeLK2 0x0000000100005aab -[CarTableViewController tableView:cellForRowAtIndexPath:object:] + 2155
4 MovieTimeLK2 0x0000000100078c7d -[PFQueryTableViewController tableView:cellForRowAtIndexPath:] + 200
5 UIKit 0x0000000101742b8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
6 UIKit 0x000000010172a836 -[UITableView _updateVisibleCellsNow:] + 2297
7 UIKit 0x000000010173b381 -[UITableView layoutSubviews] + 207
8 UIKit 0x00000001016d2b27 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
9 QuartzCore 0x00000001010c7a22 -[CALayer layoutSublayers] + 151
10 QuartzCore 0x00000001010bc589 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
11 UIKit 0x00000001016c7470 -[UIView(Hierarchy) layoutBelowIfNeeded] + 521
12 UIKit 0x00000001019a46c3 -[UISearchDisplayControllerContainerView setFrame:] + 113
13 UIKit 0x000000010199de5f -[UISearchDisplayController setActive:animated:] + 9697
14 UIKit 0x00000001019a0576 -[UISearchDisplayController searchBarTextDidBeginEditing:] + 277
15 UIKit 0x00000001018e31b0 -[UISearchBar(UISearchBarStatic) _searchFieldBeginEditing] + 97
16 UIKit 0x00000001016780ae -[UIApplication sendAction:to:from:forEvent:] + 104
17 UIKit 0x0000000101678044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
18 UIKit 0x000000010174c450 -[UIControl _sendActionsForEvents:withEvent:] + 203
19 UIKit 0x0000000101c83594 -[UITextField willAttachFieldEditor:] + 576
20 UIKit 0x00000001017513d7 -[UIFieldEditor becomeFieldEditorForView:] + 725
21 UIKit 0x0000000101c7b2df -[UITextField _becomeFirstResponder] + 143
22 UIKit 0x00000001018e5eb3 -[UISearchBarTextField _becomeFirstResponder] + 92
23 UIKit 0x000000010179fc0c -[UIResponder becomeFirstResponder] + 340
24 UIKit 0x00000001016c6abc -[UIView(Hierarchy) becomeFirstResponder] + 99
25 UIKit 0x0000000101c7ae53 -[UITextField becomeFirstResponder] + 51
26 UIKit 0x000000010198820c -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 118
27 UIKit 0x0000000101989fc0 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 1768
28 UIKit 0x000000010198050a _UIGestureRecognizerSendActions + 188
29 UIKit 0x000000010197f470 -[UIGestureRecognizer updateGestureWithEvent:buttonEvent:] + 357
30 UIKit 0x0000000101983829 __UIGestureRecognizerUpdate_block_invoke + 53
31 UIKit 0x00000001019837b1 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 257
32 UIKit 0x000000010197b87d _UIGestureRecognizerUpdate + 93
33 UIKit 0x00000001016ac925 -[UIWindow _sendGesturesForEvent:] + 928
34 UIKit 0x00000001016ad5e5 -[UIWindow sendEvent:] + 910
35 UIKit 0x0000000101686fa2 -[UIApplication sendEvent:] + 211
36 UIKit 0x0000000101674d7f _UIApplicationHandleEventQueue + 9549
37 CoreFoundation 0x0000000102c40ec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
38 CoreFoundation 0x0000000102c40792 __CFRunLoopDoSources0 + 242
39 CoreFoundation 0x0000000102c5c61f __CFRunLoopRun + 767
40 CoreFoundation 0x0000000102c5bf33 CFRunLoopRunSpecific + 467
41 GraphicsServices 0x00000001049873a0 GSEventRunModal + 161
42 UIKit 0x0000000101677043 UIApplicationMain + 1010
43 MovieTimeLK2 0x0000000100006c33 main + 115
44 libdyld.dylib 0x00000001035e65fd start + 1
45 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
From the crash log posted, it seems that your problem is in PFObject *searchUser = [self.SearchResults objectAtIndex:indexPath.row];
But that would be strange if you already use return self.SearchResults.count; in - (NSInteger) Tableview: (UITableView *) Tableview numberOfRowsInSection: (NSInteger) section
The first thing that comes to my mind is where you call [self.SearchResults removeAllObjects]; in - (void) filterResults: (NSString *)searchTerm , I suggest using the below code:
- (void) filterResults: (NSString *)searchTerm{
PFQuery * query = [PFQuery queryWithClassName: self.parseClassName]; // table in which you are looking for
[query whereKeyExists: # "mName"]; // column which you are looking for
[query whereKey: # "mName" containsString : searchTerm];
NSArray * results = [query findObjects];
self.SearchResults = [results mutableCopy];
}
Update:
Since it crashes with the first typing, then make sure that numberOfRowsInSection returns self.SearchResults.count not self.objects.count, if it does but doesn't return zero, try replacing self.searchResults = [NSMutableArray array]; with self.searchResults = [[NSMutableArray alloc] init]; in your viewDidLoad
Hope it solves your issue.
I think you don't initializate the mutable array change
self.searchResults = [NSMutableArray array];
to
self.searchResults = [NSMutableArray alloc]init];