i am creating an iPhone application with tabbar controller. I have two tabs with tableview controller. In both tabs some web service calls are there and it updates the table contents. I am using a loading indicator and all the service calls are performing on background thread and UI updates on mainthread with waitUntilDone:YES. In normal case everything is working perfect.
But the issue is,if I do sudden changes of tabs repeatedly the app crashes with error message:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x382a62a3 0x3338d97f 0x381f1b75 0x1521f9 0x362fb545 0x362e030b 0x362f77c7 0x362b3803 0x312d1d63 0x312d1901 0x312d2835 0x312d221b 0x312d2029 0x362b98eb 0x3827b6cd 0x382799c1 0x38279d17 0x381ecebd 0x381ecd49 0x3a0ec2eb 0x363042f9 0xcd317 0xc0b70)
libc++abi.dylib: terminate called throwing an exception
I know, its because try to access values from NSArray where there is no contents. But, is there any common reason for this? I mean, if I do tab changes in normal speed there is no issue. But if I try to change the tabs, just after the loading indicator ends, the app crashes. I am not able to track this on the code. Crash is happening in main.m
Please share your ideas.
Update
The issue was happening in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
at
songTitle.text = [songTitleSH objectAtIndex:indexPath.row];
albumTitle.text = [albumNameSH objectAtIndex:indexPath.row];
artistName.text = [artistNameSH objectAtIndex:indexPath.row];
commentDateLbl.text = [playDateSH objectAtIndex:indexPath.row];
i am getting NULL values in these arrays, that caused the issue. So, how can I overcome this issue? Any idea?
Related
Totally stumped on this. When I dismiss my view controller which is being presented with a custom presentation/transition in iOS 8, I get a crash on private API with this error:
*** Assertion failure in -[UICollectionView dealloc], /SourceCache/UIKit/UIKit- 3318.16.21/UICollectionView.m:665
All I know is if I remove any of these:
[self.collectionView performBatchUpdates:^{
// append your data model to return a larger size for
// cell at this index path
} completion:nil];
then it doesn't crash.
But those methods ARE NOT being called on dealloc, dismiss, viewWillDisappear. Literally anything. It's like the invocations or messages are bing stuck in some dimension and called after the view is dismissed. But I can't log them and if I try to put in logic that prevents them being called in that case, it does nothing. Which kinda makes sense: they aren't actually BEING called.
UGH! Ideas?
Update:
I just got a crash with more info (tho still opaque)
malloc: *** mach_vm_map(size=2146844672) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Update 2:
I got it to stop crashing by wrapping some code in:
[self performAfterDelay:0 block:^{
//batch updates
}];
I have a app with following structure
first i have a button in my home page when i click that it will open a new UITableView and display list of "Main Programs" When a user click on any of those will open another view controller and display all "Sub Programs" in that user can select each sub programs to see the details.
All these are working fine till iOS 7 versions. Recently i upgraded device to iOS 8 (iPad and iPhone) then i run the same code and when we return from "Sub Program Detail " page to "Sub Program" Page App is crashing. There is no log message .Only am getting this one
Please help ,The back button is working fine but something in that previous tableview controller not working .
i tried to do instrumentation then i got following message http://postimg.org/image/ytezux0m9/
Then i tried to debug it but i couldnt find anything wrong there (every value was correct) and then i tried to add "tableview relaod data" to ViewWillAppear () .And then i got a crash log like this
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISearchDisplayController numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x124e6e7a0'
*** First throw call stack:
(0x1872ee084 0x1978d40e4 0x1872f5094 0x1872f1e48 0x1871f708c 0x18be51d38 0x18bb49480 0x18bb491f4 0x18bb4fe74 0x18ba6d140 0x18ba8e4c8 0x18ba6ce58 0x18ba6ce58 0x18ba8e4c8 0x18ba6ce58 0x18ba6ce58 0x18ba6ce58 0x18ba6c528 0x18ba6c408 0x18ba77ea4 0x18bc5ab18 0x18ba7e77c 0x18bc5a3a4 0x18bc14278 0x18bb24f40 0x18bb24d0c 0x18bb24c8c 0x18ba6d874 0x18b3c5d58 0x18b3c0944 0x18b3c07e8 0x18b3bffe8 0x18b3bfd6c 0x18ba6f790 0x1872a6324 0x1872a55c8 0x1872a3678 0x1871d1664 0x1903135a4 0x18bad64f8 0x1000a4c80 0x197f42a08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Just now i run then i got this in my log
-[UITextFieldLabel numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x12fe79f70
UPDATES :
one more thing like when i going forward my if condition is true and when i click back button its geting false and execute else part for - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section method code is here http://postimg.org/image/kikrbltj1/
I think the reason for the crash is that when you click on the back button from detail, popViewController is called twice. The navigation controller firstly pops the "Sub Program Detail" page, and then immediately pops the "Sub Program" Page. In the "Sub Program" viewWillAppear method, a setupContainer method is executed and loading some FKRSearchBarTableViewController which has table to be filled.
So when the navigation controller firstly pop the "Sub Program Detail" Page, app goes to the "Sub Program" page's viewWillAppear method, where setupContainer is executed and tables are loading data, at the same time, "Sub Program" page is poped out."Sub Program" is dealloc'ed, So are the FKRSearchBarTableViewControllers, which are busy loading their tableViews. That's why message sent to dealloc'ed object.
You can move the line [self setupContainer] in DAViewController from viewWillAppear to the end of viewDidLoad, and remove the lines
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// Navigation button was pressed. Do some stuff
[self.navigationController popViewControllerAnimated:YES];
}
from viewWillDisappear in THProgramDetailsViewController.m.
Since in backBtnClick method, pop action has already been executed.
I have a button that is pressed after user enters email information. I have an alert view that is displayed when there is no email entered but if there is I want the button to segue to another view controller.
The following code causes my app to crash. I have no idea why. Please help.
(note: I have tried "sender:self]" "sender:nil]" and "sender:sender]" and they all make my app crash.)
- (IBAction)nextButtonPushed:(id)sender {
if ([self.emailTextField.text isEqual: #""]) {
emailAlertView = [[UIAlertView alloc] initWithTitle:#"Missing Email" message:#"A destination email is required to send." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[emailAlertView show];
self.nextButton.enabled = NO;
}
else {
eString = self.eTextField.text;
hString = self.hField.text;
emailAddress = self.emailTextField.text;
[userDefaults setObject:eString forKey:#"e"];
[userDefaults setObject:hString forKey:#"h"];
[userDefaults setObject:emailAddress forKey:#"email"];
[self performSegueWithIdentifier:#"next" sender:self];
}
}
There are three overwhelmingly likely possibilities:
Perhaps the storyboard really has no segue named "next" emerging from the FirstViewController scene. Be careful: spaces and capitalization and things like that matter.
Perhaps the storyboard has a segue named "next" but it emerges from a different scene (a different view controller).
Perhaps the FirstViewController instance represented by self in your code is not the same as the FirstViewController instance in the storyboard, i.e. maybe it came into existence in some other way and not by instantiation from the storyboard. You might even have two FirstViewController objects in the storyboard, and the segue comes from the other one.
One great way to figure out why your app is crashing on a line like this is to disable any breakpoints you may have (including exception breakpoints). This will cause the app to crash and often tell you a reason why it is crashing. Normally you'll get error's like #matt mentioned such as bad identifiers on your seques (often typing errors), multiple of the same object in an IB scene such as the following:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<YOURAPP.YOURVIEWCONTROLLER: 0x7c8951d0>) has no segue with identifier 'TheSequeIdentifierYouHaventSetYetOrTypedInWrong''
or like in my case today where I got this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<YOURAPP.YOURVIEWCONTROLLERYOUARETRYINGTOSHOW 0x78e5a140> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key "MyKeyOnTheOffendingObject"
Once I knew that I had an object in my storyboard with a key that it should not have all I had to do was track down the Button/Image/Other Random Object with the bad Referencing Outlet or Sent Event and all was fixed
Often performSequeWithIdentifier will come up as the last line shown before a crash since that is the last line that worked before a problem was found when presenting a new View Controller - so if you are sure the problem isn't with your seque then check references on the VC you are trying to present!
Crashing can also occur if the view controller cannot load from the NIB. For example if there is an incorrectly named User Defined Runtime Attribute.
For example QBFlatButton changed their API today and my app started crashing. This is why we use semantic versioning :-)
I am trying to pull a VC xib, by adding the view of controller on window's view. When I execute the program nothing appears (a black screen), and expectation was a button put on view of VC in xib.
But when I declare that this VC is my Project's main interface (Project Summary), then it throws the exception : terminate called throwing an exceptionsharedlibrary apply-load-rules all and application crashes.
Here is the code for didfinishlaunch (Appdelegate)
[self.window addSubview:rootViewController.view];
[self.window makeKeyAndVisible];
Can somebody assist on that.
Thanks
PS: the complete error is given below
2012-02-26 11:50:08.003 PasswordGeneratorTest[1161:f803] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
* First throw call stack:
(0x13b9052 0x154ad0a 0x13b8f11 0x9b0032 0x921f7b 0x921eeb 0x93cd60 0x22f91a 0x13bae1a 0x1324821 0x22e46e 0x230010 0x1014a 0x10461 0xf7c0 0x1e743 0x1f1f8 0x12aa9 0x12a3fa9 0x138d1c5 0x12f2022 0x12f090a 0x12efdb4 0x12efccb 0xf2a7 0x10a9b 0x1d42 0x1cb5)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
Single stepping until exit from function __pthread_kill,
which has no line number information.
I can't see your stack trace code or the message the debugger is giving you, but there's ALWAYS 2 reasons why it would crash here:
rootViewController.view is nil or doesn't have its view outlet set in IB.
self.window is not set in code or doesn't have its outlet connected in IB.
Check all of your outlets and see if it fixes it.
Introduction
In my current application I have a UITableView which holds custom cell objects. The custom UIViewCellObjects are simply subclassed from the standard UITableViewCell class. The custom cells holds information about running background uploads, and updates them with things like percentage done and so on.
The custom cell objects listens to NSNotifications from upload processes running in the background, and when they get a relevant notification, they simply update their own view controls with the new information (such as upload percentage).
Now when an upload process is done, I re-order the array of active upload objects and reload the tableview like this:
-(void) uploadFinished: (NSNotification*)notification
{
NSDictionary *userInfo = [notification userInfo];
NSNumber *uploadID = [userInfo valueForKey:#"uploadID"];
if (uploadID.integerValue == uploadActivity.uploadID)
{
[[ApplicationActivities getSharedActivities] markUploadAsFinished:uploadActivity];
[parentTable reloadData];
[self setUploadComplete];
}
}
Now this method takes place in the tableviewcell objects, and as you can see they call their owning UITableView to reload the data right after the array is sorted. The markUploadAsFinished method simply re-orders the array so any newly finished upload is put at the top, so it will appear this way in the UITableView.
The Problem
Now the problem I'm having is that when this method is called, I sometimes get the following error:
'NSInvalidArgumentException', reason: '-[CALayer tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
I do not get it all the time, sometimes the entire process runs fine and finished uploads appear in the start of the UItableview, and at other seemingly random times it fails. I don't really have a clue what's going on here.
The custom cells are loaded from a .NIB file like this:
UploadCell *cell = [activeUploadsTable dequeueReusableCellWithIdentifier:#"UploadProgressCell"];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:#"UploadCellView" owner:self options:nil];
cell = customCell;
}
Is there anyone who might have a clue about what's going on here?
EDIT
First of all, I have tracked down this error to appear right at the line where:
reloadData
is called inside of the custom cell objects.
Furthermore, it seems that the instance it sends methods to can change. I just got this error too:
'NSInvalidArgumentException', reason: '-[UIScrollViewPanGestureRecognizer tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
I really have no idea what's going on here.
'-[CALayer tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
You've got a bad pointer. It looks like your table's data source is being released while the table still exists. The table doesn't retain its data source because that could create a retain cycle. If you don't take care to keep the data source around while the table is using it, the table will can up with a pointer to an object that no longer exists. In this case, it looks like a CALayer object is subsequently being created at the same address. When the table later sends its "data source" a message to get the number of rows, that message is delivered to the layer, which (obviously) doesn't have a -tableView:numberOfRowsInSection: method, and the error results.
According to me you running the upload process method in background i think other thread than main thread. And according to my knowledge when you deal with UIKIT objects you have ruin on main thread.
But these problem not occur every time because some time you switch to other thread to main thread so its working fine and some time not. so that problem occur