In
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil parentController:(GameViewController *)myGameController{
Have a series of transforming labels like so:
deg90 = 1.570796326794897;
//....transforms
background.center = CGPointMake(160,230);
background.transform = CGAffineTransformMakeRotation(deg90);
BetLabel.text = #"test";
BetLabel.transform = CGAffineTransformMakeRotation(deg90);
That last line is crashing me with:
2010-04-13 21:04:47.858 Game[1204:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'
2010-04-13 21:04:47.893 Game[1204:207] Stack: (
864992541,
859229716, (lots of numbers)
But if I comment it out, I get the text changing fine.
Update: Uh oh, just did a test.. turns out the other transforms were on UIImageViews. Apparently rotating a label in this xib is causing the crash.
But in another file the transforms are working fine:
newprofileentry.transform = CGAffineTransformMakeRotation(1.570796326794897);
playerb0.transform = CGAffineTransformMakeRotation(1.570796326794897);
playerb1.transform = CGAffineTransformMakeRotation(1.570796326794897);
Tried substituting deg90 with the full float value, still the same crash.
Tried cleaning cache, restarting IB and Xcode, cleaning all targets. Program has been running fine until I just added these labels. Tried deleting the label, readding and reconnecting the Outlet, too.
Thanks for reading, hope someone has an idea about this.
Cheers!
I suggest moving the transforms out of initWithNib: It's possible that the you're trying to modify something that doesn't yet exist because the objects in the nib are still initializing.
You should also examine the nib file (in Interface Builder or with ibtool) to see if there is something scrambled with that particular label. To test that, you could swap out its order in the initialization with another label to see if the problem is with that particular label or whether it is with any label or object in the last position.
Posting more code in context would probably help.
Related
I'm making an iOS 6 program which downloads JSON data from a website and displays it in a table view. I added a pull to refresh method witch works fine. I can go in the settings view controller (secondViewController) and change the address, everything works. Then, I use the pull to refresh method and my tableView is reloaded. But if I reload 3 times AFTER changing the address, my app crashes. I get this error :
*** Terminating app due to uncaught exception 'NSRangeException',
reason: '*** -[__NSArrayM objectAtIndex:]: index 10 beyond bounds for empty array'
*** First throw call stack:
(0x1ca1012 0x10dee7e 0x1c430b4 0x3084 0xdd8fb 0xdd9cf 0xc61bb 0xd6b4b 0x732dd 0x10f26b0 0x229dfc0 0x229233c 0x2292150 0x22100bc 0x2211227 0x22bb333 0x22bb75f 0x1c60376 0x1c5fe06 0x1c47a82 0x1c46f44 0x1c46e1b 0x1bfb7e3 0x1bfb668 0x22ffc 0x1fbd 0x1ee5)
libc++abi.dylib: terminate called throwing an exception
What am I doing wrong ? And how can I fix that problem ? Thanks for your help !
The key design consideration that leaps out is that your retreiveData method is clearly updating the model (the citiesArray) asynchronously, which means that any interaction with the tableview while this is taking place may fail. You should never asynchronously update the actual citiesArray itself. The update to that array should happen in the main queue.
You should change retrieveData to not touch the existing citiesArray, but rather create and return a new array, and then, in the code you dispatch back to the main queue, only then replace the existing citiesArray and call reloadData, something like:
- (void)refresh:(UIRefreshControl *)refreshControl {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSArray *newCitiesArray = [self retreiveData];
dispatch_async(dispatch_get_main_queue(), ^{
if (newCitiesArray) {
// you presumably only want to reload the data if `retrieveData` was successful
citiesArray = newCitiesArray
[myTableView reloadData];
}
[refreshControl endRefreshing];
});
});
}
Clearly, this will involve some changes to retrieveData, too, but hopefully that's self explanatory. If not, update your question with that code, and we can make further suggestions. But we really shouldn't need to go there, as I suspect you understand the change that needs to take place there.
There are other, more subtle issues you might want to tackle, too, such as thinking about whether you really want to use a global queue, which is concurrent (e.g. if you hit refresh while the previous refresh going, do you really want two queries going on concurrently with your server ... because you dispatch the updates back to the main queue you won't crash, but it's inefficient, you're not guaranteed the order that they'll complete, etc.). You might also want to use NSOperationQueue in which you can write code to permit the cancellation of previous requests, etc.
But all of this is a little complicated and is of secondary concern to your main issue, the crashing. Refactoring the retrieveData code to ensure you don't touch citiesArray, itself, as outlined above, should address that.
I have developed an app that in testing has worked fine but when it has could live I have had some issues with crashes when presenting Modal View Controllers. The issue is in here some where:
NSLog(#"Looks like we made it here 1");
UIViewController *mtaViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"mtaViewController"];
NSLog(#"Looks like we made it here 2");
[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
NSLog(#"Looks like we made it here 3");
[self presentModalViewController:mtaViewController animated:YES];
NSLog(#"Looks like we made it here 4");
and my output to the console is:
2012-06-14 09:26:24.161 appname[2013:707] Looks like we made it here 1
2012-06-14 09:26:24.165 appname[2013:707] Looks like we made it here 2
2012-06-14 09:26:24.166 appname[2013:707] Looks like we made it here 3
2012-06-14 09:26:28.866 appname[2013:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x343ac8bf 0x345fc1e5 0x342f5b6b 0x6d3fd 0x6e719 0x3778e7ff 0x37798d53 0x37798cc1 0x37838339 0x3783714f 0x37891d97 0x7ce1d 0x7cd47 0x3788eaa5 0x3776a81b 0x3776ffb9 0x34ec1ba7 0x36fe0e8d 0x3437f2dd 0x343024dd 0x343023a5 0x30b86fcd 0x37783743 0x84327 0x6b468)
terminate called throwing an exception
I have set up in a function that I call when wanting to change view controllers and as you can see it makes it all the way down to "Looks like we made it here 3" so I suspect that there is an issue with line
[self presentModalViewController:mtaViewController animated:YES];
Can anyone help?
Check any array in mtaViewController, I dont see any array in your code so I'm thinking the issue is within mtaViewController. :)
Are you sure you view controller really gets initialized? Just an idea but this line
[mtaViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
would do nothing if mtaViewController would be nil. In Cocoa you can send messages to nil without problems. Your app only will crash later when you try to do something specific with them. Does
NSLog(#"%#", mtaViewController);
tell you something useful? Please make also sure you connected everything in IB that has to be connected (if you aren't working everything out in raw code).
By the way. This is deprecated. Use
presentViewController:animated:completion:
instead.
I get the following error while running my app.
'-[NSCFString sizeWithTextStyle:]: unrecognized selector
I have not used sizeWithTextStyle in my entire project.
So what could be wrong?
I get error on return pos; statement below
Code:
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *pos = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,35.0)];
return pos;
}
Error in Console:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString sizeWithTextStyle:]: unrecognized selector sent to instance 0x7044b50'
Because of indentation problem while putting whole crash log here, I am putting the screenshot of the crash log
I think, the problem is somewhere else, not in this line of code. The object is not able to retain itself. Post the code, where you are using the sizeWithTextStyle method
Have you the -all_load flag on your link settings?
This issue comes up a lot. You need to add -all_load and -ObjC to your applications link flags.
*EDIT : *
Crash appears to occur on line:
CGSize textSize = [self.text sizeWithTextStyle:textStyle];
in class: CPTextLayer method: sizeToFit
which is called from within class CPTextLayer method initWithText:
-(id)initWithText:(NSString *)newText style:(CPTextStyle *)newStyle
....
[self sizeToFit];
**try to set with iOS 4 and not with 3.1.3 **
When you have memory management issues (selectors being sent to the wrong instances is one symptom of memory management issues), there are a number of things you can do:
Re-read the Cocoa memory management rules and make sure that you're following them.
Run the static analyser. This will often pick up places where you have neglected the memory management rules.
Try using NSZombieEnabled to find out whether [and when] you are sending messages to unallocated instances.
I am also getting same error but now it's solved.
Need to do simple thing, set the value of Other linker flag.
below I have mention the steps.
Project name - Build Setting - Other linker flag (use search bar to search) - "-ObjC"
You should change your code to use pointers like this:
UIView *pos = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,35.0)];
return pos;
Pay attention to asterisk!
And of course the ; in the end of allocation statement!
I have a navigation based app that uses Core Data for storage. The schema for this particular section is as follows:
Scene hasMany Tasks hasMany DeviceCommands
Tasks also have many other objects besides DeviceCommands (like DelayCommands etc), but this is beyond the scope of the problem (I think).
DeviceCommands also link to a parent object as follows:
Device hasMany DeviceCommands
Now, the user can create a new Task, which pops up a modal view to select the Device. When you select a device, a tableview is pushed with the DeviceCommands that belong to the Device. When you select a DeviceCommand, it assigns it to the Task with task.deviceCommand = device.deviceCommand. For some reason, and this only happens in this section of the app, the app crashes with the following output in the console:
2010-10-26 15:37:33.337 livOS4[47226:207] Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. * -[NSMutableArray objectAtIndex:]: index 35 beyond bounds [0 .. 0] with userInfo (null)
Index 35 refers to the index of the DeviceCommand in the UITableView and NSFetchedResultsController. Through a process of trial and error I've discovered that the NSMutableArray is the array with the Devices. If I add a new Device to the app, the array bounds are [0 .. 1].
I added an observer for NSManagedObjectContextObjectsDidChangeNotifications but it crashes before the observer receives anything.
Can anyone help or offer any advice for fixing this?
I have the same problems with NSFetchedResultsController.
Problem disappear then I add this to my viewController
- (void)dealloc
{
self.fetchedResultsController.delegate = nil;
self.fetchedResultsController = nil;
}
Fixed it this morning. Turned out to be a problem with how I was assigning the NSFetchedResultsController delegate.
IET ANOTHER EDIT (to increase strangeness)
EDITED to show the relevant part of the code
Hi. There's a strange problem with an NSMutableArray which I'm just not understanding...
Explaining:
I have a NSMutableArray, defined as a property (nonatomic, retain), synthesized, and initialized with 29 elements.
realSectionNames = [[NSMutableArray alloc] initWithCapacity:29];
After the initialization, I can insert elements as I wish and everything seems to be working fine.
While I'm running the application, however, if I insert a new element in the array, I can print the array in the function where I inserted the element, and everything seems ok.
However, when I select a row in the table, and I need to read that array, my application crashes. In fact, it cannot even print the array anymore.
Is there any "magical and logical trick" everybody should know when using a NSMutableArray that a beginner like myself can be missing?
Thanks a lot.
I declare my array as
realSectionNames = [[NSMutableArray alloc] initWithCapacity:29];
I insert objects in my array with
[realSectionNames addObject:[category categoryFirstLetter]];
although I know i can also insert it with
[realSectionNames insertObject:[category categoryFirstLetter] atIndex:i];
where the "i" is the first non-occupied position.
After the insertion, I reload the data of my tableView. Printing the array before or after reloading the data shows it has the desired information.
After that, selecting a row at the table makes the application crash. This realSectionNames is used in several UITableViewDelegate functions, but for the case it doesn't matter. What truly matters is that printing the array in the beginning of the didSelectRowAtIndexPath function crashes everything (and of course, doesn't print anything). I'm pretty sure it's in that line, for printing anything he line before works (example):
NSLog(#"Anything");
NSLog(#"%#", realSectionNames);
gives the output:
2010-03-24 15:16:04.146 myApplicationExperience[3527:207] Anything
[Session started at 2010-03-24 15:16:04 +0000.]
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 3527.
Still not understanding what kind of stupidity I've done this time... maybe it's not too late to follow the career of brain surgeon?
following an answer, i printed
NSLog(#"self=%x", self);
NSLog(#"self=%#", self);
NSLog(#"realSectionNames=%x", realSectionNames);
gives the exact same results in every function (from delegate or not).
NSLog(#"realSections = %#", realSectionNames);
prints well in my viewWillAppear, in the didSelectRowAtIndexPath, and crashes in viewForHeaderInSection. No threading, by the way...
So, without knowing what to do, I'm trying "things"... I changed all references of realSectionNames to self.realSectionNames
printing in the viewForHeaderInSection gives the following problem:
2010-03-24 16:01:44.067 myApplication[4104:207] numberOfSectionsInTableView result -> 1
2010-03-24 16:01:44.068 myApplication[4104:207] viewForHeaderAtSection
2010-03-24 16:01:44.068 myApplication[4104:207] self=3d13470
2010-03-24 16:01:44.068 myApplication[4104:207] self=<RootViewController: 0x3d13470>
2010-03-24 16:01:44.069 myApplication[4104:207] self.realSectionNames=3b12830
2010-03-24 16:01:44.070 myApplication[4104:207] realSections = (
<__NSArrayReverseEnumerator: 0x3b50500>
)
2010-03-24 16:01:44.070 myApplication[4104:207] *** -[__NSArrayReverseEnumerator length]: unrecognized selector sent to instance 0x3b50500
2010-03-24 16:01:44.071 myApplication[4104:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayReverseEnumerator length]: unrecognized selector sent to instance 0x3b50500'
2010-03-24 16:01:44.072 myApplication[4104:207] Stack: (
31073371,
2572170505,
31455291,
31024758,
30877378,
276908,
26404,
3227182,
4544033,
4551926,
4550923,
3267462,
3207973,
3249408,
25927,
3222086,
3205252,
459178,
30857920,
30854216,
39163413,
39163610,
2949039
)
What is a NSArrayReverseEnumerator??? And why is it being mean to me???
Note to everybody (and specially to self)...
I'm a dumb, dumb boy.
I was releasing an element which I inserted in the array.
Sorry for the questions, thanks for the answers...
When an application crashes, the Xcode Console will report the error that caused the application to crash. You will want to edit your question to include this error message, along with relevant source code, as this will help others answer your question.
I suspect your selected table row is trying to point to an index in the array, which does not exist. If so, you're trying to reference a part of the array that does not exist. This causes your application to throw an exception and quit.
Remember that an NSMutableArray can be initialized to a certain capacity, but until items are inserted, it does not actually hold any objects. The -initWithCapacity: method only sets aside a certain amount of memory, but there are no placeholders or nil entries for 1 through n indices.
1) Could we know the error message ? and the relevant part of the code ?
2) Here is the proper way to declare your array :
self.realSectionNames = [[NSMutableArray arrayWithCapacity:29];
I suspect your TableView's delegate isn't hooked up correctly, or is connected to an invalid object. Are any of your other delegate methods working? Try putting these at the top of didSelectRowAtIndexPath to check the pointer values:
NSLog(#"self=%x", self);
NSLog(#"self=%#", self);
NSLog(#"realSectionNames=%x", realSectionNames);