In my game, when I load a new level, the previous level seems to be still remaining in the view.. Each level has its own class and they all draw something on the screen. So if I have 2 or more levels of images loaded, that makes my game too slow. What can I do to unload the previous level? Thanks in advance..
- (void) finishedLevel: (Level *) level
{
levelNumber++;
levelClass = NSClassFromString([NSString stringWithFormat:
#"Level_%d", levelNumber]);
if (!levelClass) levelClass = [Level class];
currentLevel = [[levelClass alloc] initWithView: self.mainView];
self.mainView.levelLabel.text = [NSString stringWithFormat:#"Level %d", levelNumber];
gameRunning = NO;
}
I tried using the following but didn't really work
levelClass = NSClassFromString([NSString stringWithFormat:#"Level_%d", levelNumber-1]);
[levelClass removeFromSuperview];
Error message
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[Level_1 removeFromSuperview]: unrecognized selector sent to class 0x107644'
Related
I get this error:
-[MPInlineVideoFullscreenViewController player]: unrecognized selector sent to instance 0x15e63fe90
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MPInlineVideoFullscreenViewController player]: unrecognized selector sent to instance 0x15e63fe90'
Using iOS 8, the language is Objective-C. But I have this same code in the if statement like this in applicationDidBecomeActive and it does not crash:
UIViewController *vc = ((UINavigationController*)self.window.rootViewController).visibleViewController;
if([vc isKindOfClass:[VideoViewController class]]) {
VideoViewController *vca = vc;
if(vca.player.playbackState == MPMoviePlaybackStatePaused){
[vca.player play];
}
But if I use it on the different MPMoviePlayer, and it is fullscreen. I switch to a different app, and back, it crashes. Buy why not with the other movie controller. Also, the other one does not show any playback controls, while this one which crashes does.
i have created one custom cell and put button on it
and button event is like this
[cell.BtnRequest addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
and didtapbutton code is this
- (void)didTapButton:(id)sender {
WorkerDetailsVC *wvc=[self.storyboard instantiateViewControllerWithIdentifier:#"workerdetailsvc"];
NSIndexPath *indepath = [self.tblorderdata indexPathForCell:sender];
wvc.arrworkarrequest=[arrData objectAtIndex:indepath.row];
NSLog(#" arr send :%#", wvc.arrworkarrequest);
wvc.struserid = struserid;
[self.navigationController pushViewController:wvc animated:YES];
}
and on the next page i got the array arrworkarrequest and after the load all next page it will show error like this
2014-10-01 15:08:42.607 demo[2151:60b] -[__NSCFNumber length]: unrecognized selector sent to instance 0x911a860
2014-10-01 15:08:42.613 dmeo[2151:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x911a860'
Your problem is that sender is of type UIButton not UITableViewCell so it's getting stuck in the [self.tblorderdata indexPathForCell:sender] because that method call expects a type of UITableViewCell.
You need to find the Cell that the button is in. You may be able to do this using a while loop (although it's a bit horrible). Something like:
id obj = sender;
while (![obj isKindOfClass:[UITableViewCell class]]) {
obj = [sender superview];
}
[self.tblorderdata indexPathForCell:obj];
This feels like it's abusing the view hierarchy though.
This happens if you compare the length of a string directly
for example
NSString *myString = #"2";
using this statement will generate the error
if(myString.length==2)
I want to design a level select scene in my game. What I want is a very abstract design which consists of a single UIPickerView that has the width of the screen and about 200 px in height.
The following is from LevelSelect.m , which is a subclass of SKScene
-(id)initWithSize:(CGSize)size{
if (self = [super initWithSize:size]) {
/* Setup your scene here */
self.backgroundColor = [SKColor whiteColor];
for (int i = 0; i < 10; i++) {
NSString* levelString = [NSString stringWithFormat:#"Level %i",i];
[levelData setObject:levelString atIndexedSubscript:i];
}
UIPickerView *levelPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(self.scene.size.width/2, self.scene.size.height/2, self.scene.size.width, 200)];
levelPickerView.dataSource = self;
levelPickerView.delegate = self;
levelPickerView.showsSelectionIndicator = YES;
[self addChild:levelPickerView];
}
return self;
}
I implemented the UIPickerView data source and delegate methods. But when i load the scene i get the following error .
2014-07-23 22:32:41.222 Poppolo[13686:60b] -[UIPickerView setPaused:]: unrecognized selector sent to instance 0x17d90470
2014-07-23 22:32:41.225 Poppolo[13686:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPickerView setPaused:]: unrecognized selector sent to instance 0x17d90470'
* First throw call stack:
(0x2dd30f0b 0x384c7ce7 0x2dd34837 0x2dd33137 0x2dc82098 0x304618cb 0xe1f3d 0xe70fb 0x389b0d53 0x389b0d3f 0x389b36c3 0x2dcfb681 0x2dcf9f4d 0x2dc64769 0x2dc6454b 0x32bd16d3 0x305c3891 0xee221 0x389c5ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
thanks in advance.
I have a view controller opening an 'Open-In' dialogue via a bar button item.
Calling code:
UIDocumentInteractionController *docInteraction = [[UIDocumentInteractionController alloc] init];
docInteraction.URL = location;
docInteraction.delegate = self;
if ([docInteraction presentOpenInMenuFromBarButtonItem:self.openInButton animated:YES])
self.openInController = docInteraction;
Dismissal code:
UIDocumentInteractionController *openIn = self.openInController;
if (openIn) {
[openIn dismissMenuAnimated:animated];
self.openInController = nil;
popupsDismissed = YES;
}
Sometime after the code is dismissed, the app crashes with this exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[A2DynamicUIPopoverControllerDelegate popoverController:animationCompleted:]: unrecognized selector sent to instance 0x1f82b4f0'
This is a BlocksKit defined interface, but I'm not using a BlocksKit class in thie particular case. 0x1f82b4f0 is a <A2DynamicDelegate: 0x1f82b4f0; protocol = UIPopoverControllerDelegate> but why BlocksKit is involved here at all is a mystery. Can someone give me some insight on how to fix the exception?
BlocksKit is a bit of a red herring. The dismissal code is deallocating the UIDocumentInteractionController too early here:
self.openInController = nil;
At the earliest, the deallocation should happen after the -documentInteractionControllerDidDismissOpenInMenu: delegate callback method.
I'm trying to create this application, when you press on a tablecell you get shown the ViewController, and the variable get's set in the other view controller. Although i'm getting a few errors when i press the uitablecell.
Error:
2013-04-06 22:47:25.970 iFSX Guide[1069:907] Called
2013-04-06 22:47:26.009 iFSX Guide[1069:907] -[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390
2013-04-06 22:47:26.016 iFSX Guide[1069:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390'
*** First throw call stack:
(0x319b22a3 0x3964c97f 0x319b5e07 0x319b4531 0x3190bf68 0x33832beb 0x338a837f 0x338548fb 0x33a95619 0x338a79b9 0x338a5fe7 0x339c83ef 0xa22a5 0x3387c28d 0x338fef81 0x322c0277 0x319875df 0x31987291 0x31985f01 0x318f8ebd 0x318f8d49 0x354ba2eb 0x3380e301 0xa19d1 0x39a83b20)
libc++abi.dylib: terminate called throwing an exception
The code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)in dexPath{
NSLog(#"Called");
Aircraft = indexPath.row;
[self performSegueWithIdentifier:#"ToSections" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"ToSections"]){
AirplaneSections *sections = (AirplaneSections *)segue.destinationViewController;
sections.plane = Aircraft;
}
}
I've found out that it's an error on ViewDidLoad on the viewcontroller.
NSString *quickTemp = [NSString alloc];
switch (plane) {
case 0:
quickTemp = #"Boeing 737-800";
break;
default:
break;
}
TitleLabel.text = quickTemp;
*/
I'm doing something wrong there.
Are you using ARC? This sort of problem usually indicates there's a memory error somewhere. Basically, some code somewhere is trying to access an object that was already released. This makes everything go kaboom.
If you aren't using ARC, you should turn it on.
After that, the next thing you should do is run the static analyzer. Fix anything that comes up.
If that doesn't fix the problem, in Xcode, add a breakpoint that stops when an Objective-C exception is thrown. It should show you where exactly this problem is happening.
If that doesn't help, run your code under Instruments' and the Zombie tool. This will show you exactly where you tried to access memory that was already released.