MPMoviePlayer crashing app on device but not in simulator, but only when trying to play some files - mpmovieplayer

I am writing an app that displays videos using MPMoviePlayer which are stored locally on the device. When I try to play most of the videos, the app crashes on the device, but not on the simulator where they play fine. I am using the same code to play all of the videos, I have tried deleting and reinstalling the app, cleaning then building again, with no luck.
The simulator is version 4.3 and the iPad I am testing the app on is version 4.3.1. I am using Xcode 4
This is the code I am using to play one of the videos that crashes:
#implementation SinglePendulumControl
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"SinglePendulumControl" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
[[self view] setBounds:CGRectMake(0, 0, 1024, 768)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
This is the code I am using to play one of the videos that doesn't crash:
#implementation GlueSettings
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"gluesettings" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
[[self view] setBounds:CGRectMake(0, 0, 1024, 768)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
The console log of the crash:
May 16 17:55:31 unknown Vector[3590] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** Call stack at first throw:
(
0 CoreFoundation 0x33c3d64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x33f01c5d objc_exception_throw + 24
2 CoreFoundation 0x33c3d491 +[NSException raise:format:arguments:] + 68
3 CoreFoundation 0x33c3d4cb +[NSException raise:format:] + 34
4 Foundation 0x36da018f -[NSURL(NSURL) initFileURLWithPath:] + 70
5 Foundation 0x36da012f +[NSURL(NSURL) fileURLWithPath:] + 30
6 Vector 0x000eb7e5 -[BumpBarBumpSwitch playMovie:] + 80
7 CoreFoundation 0x33bad571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
8 UIKit 0x31f43ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
9 UIKit 0x31f43e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
10 UIKit 0x31f43e3b -[UIControl sendAction:to:forEvent:] + 38
11 UIKit 0x31f43b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
12 UIKit 0x31f44423 -[UIControl touchesEnded:withEvent:] + 342
13 UIKit 0x31f42bf5 -[UIWindow _sendTouchesForEvent:] + 368
14 UIKit 0x31f4256f -[UIWindow sendEvent:] + 262
15 UIKit 0x31f2b313 -[UIApplication sendEvent:] + 298
16 UIKit 0x31f2ac53 _UIApplicationHandleEvent + 5090
17 GraphicsServices 0x3257ee77 PurpleEventCallback + 666
18 CoreFoundation 0x33c14a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
19 CoreFoundation 0x33c1683f __CFRunLoopDoSource1 + 166
20 CoreFoundation 0x33c1760d __CFRunLoopRun + 520
21 CoreFoundation 0x33ba7ec3 CFRunLoopRunSpecific + 230
22 CoreFoundation 0x33ba7dcb CFRunLoopRunInMode + 58
23 GraphicsServices 0x3257e41f GSEventRunModal + 114
24 GraphicsServices 0x3257e4cb GSEventRun + 62
25 UIKit 0x31f55d69 -[UIApplication _run] + 404
26 UIKit 0x31f53807 UIApplicationMain + 670
27 Vector 0x000e9f31 main + 48
28 Vector 0x000e9efc start + 40
)
May 16 17:55:31 unknown UIKitApplication:Vector-Systems.Vector[0xc457][3590] <Notice>: terminate called after throwing an instance of 'NSException'
May 16 17:55:31 unknown ReportCrash[3591] <Notice>: Formulating crash report for process Vector[3590]
May 16 17:55:31 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:Vector-Systems.Vector[0xc457]) Job appears to have crashed: Abort trap: 6
May 16 17:55:31 unknown SpringBoard[29] <Warning>: Application 'Vector' exited abnormally with signal 6: Abort trap: 6
May 16 17:55:31 unknown ReportCrash[3591] <Error>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/Vector_2011-05-16-175531_Duncans-iPad.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0
May 16 17:55:34 unknown DTPower[3080] <Warning>: Task info failed for task Vector-Systems.Vector

Related

Getting NSGeneric Exception while updating constraints programmatically?

Here is my code:
int x= 17;
int y = 27;
int width = 287;
int height = 181;
int mainview_height = 568;
int x_spacer = 0;
int y_spacer = 0;
int width_spacer = 320;
int height_spacer = 27;
UIView *view_spacer = [[UIView alloc]initWithFrame:CGRectMake(x_spacer, y_spacer, width_spacer, height_spacer)];
[view_spacer setBackgroundColor:[UIColor clearColor]];
[view_spacer setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.mainView addSubview:view_spacer];
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
[view1 setBackgroundColor:[UIColor whiteColor]];
[view1 setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.mainView addSubview:view1];
[view_spacer addConstraint:[NSLayoutConstraint constraintWithItem:view_spacer attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual toItem:view_spacer attribute:NSLayoutAttributeHeight multiplier:width_spacer/height_spacer constant:0.0f]];
[self.mainView addConstraint:[NSLayoutConstraint constraintWithItem:view_spacer attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeTop multiplier:1 constant:0.0f]];
[self.mainView addConstraint:[NSLayoutConstraint constraintWithItem:view_spacer attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeHeight multiplier:width_spacer/mainview_height constant:0.0f]];
[self.mainView addConstraint:[NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view_spacer attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
[view_spacer addConstraint:[NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view_spacer attribute:NSLayoutAttributeBottom multiplier:1 constant:0.0f]];
[view1 addConstraint:[NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual toItem:view1 attribute:NSLayoutAttributeHeight
multiplier:width/height constant:0.0f]];
[self.mainView addConstraint:[NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeHeight multiplier:width/mainview_height constant:0.0f]];
[self.mainView addConstraint:[NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view1 attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
I got the following error while updating the auto layout constraints
The view hierarchy is not prepared for the constraint:
When added to
a view, the constraint's items must be descendants of that view (or
the view itself). This will crash if the constraint needs to be
resolved before the view hierarchy is assembled. Break on -[UIView
_viewHierarchyUnpreparedForConstraint:] to debug. 2015-07-18 12:54:02.469 LandCorp Cleaning App[2022:64687] View hierarchy
unprepared for constraint. Constraint:
Container
hierarchy: > View not found in container hierarchy:
> That view's superview: > 2015-07-18 12:54:02.472 LandCorp Cleaning
App[2022:64687] * Terminating app due to uncaught exception
'NSGenericException', reason: 'Unable to install constraint on view.
Does the constraint reference something from outside the subtree of
the view? That's illegal.
constraint: view:>'
* First throw call stack: ( 0 CoreFoundation 0x000000010799dc65 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000107636bb7 objc_exception_throw + 45 2 CoreFoundation
0x000000010799db9d +[NSException raise:format:] + 205 3 Foundation
0x00000001071c8479 -[NSLayoutConstraint
_addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 187 4 UIKit 0x0000000108406786 -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]
+ 411 5 UIKit 0x0000000108406a14 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:]
+ 30 6 UIKit 0x0000000108406b3c -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 243 7 LandCorp Cleaning App 0x00000001070e7e47 -[InspectionDetails populateDataViews] + 2007 8 LandCorp Cleaning App 0x00000001070e748c -[InspectionDetails
connection:didReceiveData:] + 1404 9 CFNetwork
0x00000001097dbd6c __65-[NSURLConnectionInternal
_withConnectionAndDelegate:onlyActive:]_block_invoke + 69 10 CFNetwork 0x00000001097dbd10
-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199 11 CFNetwork 0x00000001097dbe77
-[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48 12 CFNetwork 0x00000001097c6089
_ZL30_NSURLConnectionDidReceiveDataP16_CFURLConnectionPK8__CFDatalPKv + 79 13 CFNetwork 0x00000001096a85e0 ___ZN27URLConnectionClient_Classic29_delegate_didReceiveDataArrayEv_block_invoke
+ 302 14 CFNetwork 0x0000000109778a71 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2
+ 273 15 CFNetwork 0x00000001096965d6 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72 16 CoreFoundation 0x00000001078a4354 CFArrayApplyFunction + 68 17 CFNetwork
0x0000000109696497 _ZN19RunloopBlockContext7performEv + 133 18
CFNetwork 0x00000001096962d6
_ZN17MultiplexerSource7performEv + 256 19 CFNetwork 0x00000001096960ec _ZN17MultiplexerSource8_performEPv + 72 20
CoreFoundation 0x00000001078d1431
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 21 CoreFoundation 0x00000001078c72fd
__CFRunLoopDoSources0 + 269 22 CoreFoundation 0x00000001078c6934 __CFRunLoopRun + 868 23 CoreFoundation
0x00000001078c6366 CFRunLoopRunSpecific + 470 24 GraphicsServices
0x000000010aec3a3e GSEventRunModal + 161 25 UIKit
0x0000000107d968c0 UIApplicationMain + 1282 26 LandCorp Cleaning App
0x00000001070e897f main + 111 27 libdyld.dylib
0x0000000109f41145 start + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException

iOS8 app getting crash while opening popover

This is the code that I have written and it is in the method when the user selects the popover:
- (IBAction) onSelectingDefect:(id)sender
{
if ([description isFirstResponder]) {
[self hideKeyBoard];
return;
}
UIButton *button = (UIButton*)(sender);
UIButton *doneSelectingStatusButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneSelectingStatusButton.frame = CGRectMake(85, 223, 149, 32);
[doneSelectingStatusButton setTintColor:[UIColor blackColor]];
[doneSelectingStatusButton setTitle:#"Done" forState:UIControlStateNormal];
[doneSelectingStatusButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[doneSelectingStatusButton setBackgroundImage:[UIImage imageNamed:#"cancel_button02.png"] forState:UIControlStateNormal];
[doneSelectingStatusButton addTarget:self action:#selector(onPickerSelection:) forControlEvents:UIControlEventTouchUpInside];
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
pickerView.showsSelectionIndicator = YES;
pickerView.delegate = self;
pickerView.dataSource = self;
BOOL isNill = TRUE;
int i;
for(i=0; i<[tableData count]; i++)
{
if([selectedPickerText isEqualToString:[tableData objectAtIndex:i]])
{
isNill = FALSE;
break;
}
}
if(isNill)
{
[pickerView selectRow:0 inComponent:0 animated:YES]; //Orig
//self.selectedPickerText = [tableData objectAtIndex:0];
self.selectedPickerText = [tableData objectAtIndex:0];
}
else
[pickerView selectRow:i inComponent:0 animated:YES];//Orig
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 255)];
[containerView addSubview:doneSelectingStatusButton];
[containerView addSubview:pickerView];
UIViewController *pickerViewController = [[UIViewController alloc] init];
CGRect myRect = button.frame;
myRect.origin.x += 10;
myRect.origin.y += 10;
selectionPopover = [[UIPopoverController alloc] initWithContentViewController:pickerViewController];
((AppDelegate*) [UIApplication sharedApplication].delegate).secondPopOver = selectionPopover;
selectionPopover.delegate =self;
selectionPopover.popoverContentSize = CGSizeMake(320, 255);
[selectionPopover presentPopoverFromRect:selectDefect.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //Error iOS8
pickerViewController.view = containerView;
[containerView release];
[pickerView release];
[pickerViewController release];
}
This is the error I am geting:
2014-11-04 20:01:30.740 Service360[447:5288] -[UITextField length]: unrecognized selector sent to instance 0x7f0d6520
2014-11-04 20:01:30.743 Service360[447:5288] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField length]: unrecognized selector sent to instance 0x7f0d6520'
*** First throw call stack:
(
0 CoreFoundation 0x0321f946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x02d01a97 objc_exception_throw + 44
2 CoreFoundation 0x032275c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x031703e7 ___forwarding___ + 1047
4 CoreFoundation 0x0316ffae _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x03108d26 CFStringAppend + 374
6 CoreFoundation 0x0310684a __CFStringAppendFormatCore + 11754
7 CoreFoundation 0x031fc5f5 _CFStringCreateWithFormatAndArgumentsAux2 + 245
8 Foundation 0x028b7697 -[NSPlaceholderString initWithFormat:locale:arguments:] + 159
9 Foundation 0x028baf42 +[NSString stringWithFormat:] + 89
10 UIKit 0x0183dd34 -[UIViewController _presentViewController:withAnimationController:completion:] + 2825
11 UIKit 0x018405d2 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
12 UIKit 0x01840424 -[UIViewController presentViewController:animated:completion:] + 224
13 UIKit 0x01db0791 -[UIPopoverController _presentShimmedPopoverFromRect:inView:permittedArrowDirections:animated:] + 217
14 UIKit 0x01db0991 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 355
15 Service360 0x00369b52 -[POVendorFeedbackViewController onSelectingDefect:] + 2770
16 libobjc.A.dylib 0x02d177cd -[NSObject performSelector:withObject:withObject:] + 84
17 UIKit 0x016da23d -[UIApplication sendAction:to:from:forEvent:] + 99
18 UIKit 0x016da1cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
19 UIKit 0x0180de86 -[UIControl sendAction:to:forEvent:] + 69
20 UIKit 0x0180e2a3 -[UIControl _sendActionsForEvents:withEvent:] + 598
21 UIKit 0x0180d50d -[UIControl touchesEnded:withEvent:] + 660
22 UIKit 0x0172a60a -[UIWindow _sendTouchesForEvent:] + 874
23 UIKit 0x0172b0e5 -[UIWindow sendEvent:] + 791
24 UIKit 0x016f0549 -[UIApplication sendEvent:] + 242
25 Service360 0x00068f22 -[MyApplication sendEvent:] + 178
26 UIKit 0x0170037e _UIApplicationHandleEventFromQueueEvent + 20690
27 UIKit 0x016d4b19 _UIApplicationHandleEventQueue + 2206
28 CoreFoundation 0x031431df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x03138ced __CFRunLoopDoSources0 + 253
30 CoreFoundation 0x03138248 __CFRunLoopRun + 952
31 CoreFoundation 0x03137bcb CFRunLoopRunSpecific + 443
32 CoreFoundation 0x031379fb CFRunLoopRunInMode + 123
33 GraphicsServices 0x044b424f GSEventRunModal + 192
34 GraphicsServices 0x044b408c GSEventRun + 104
35 UIKit 0x016d88b6 UIApplicationMain + 1526
36 Service360 0x0006793f main + 159
37 libdyld.dylib 0x077a7ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
THe line which is causing the app to crash is:
[selectionPopover presentPopoverFromRect:selectDefect.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //Error iOS8
What can be the issue which is causing this error. The app works fine in earlier or previous releases of iOS.
Can you pls help me?
Thanks
As of ios8 you need a UIPopoverPresentationController For the popovercontroller.
if ( NSClassFromString(#"UIPopoverPresentationController") ) {
selectionPopover.popoverPresentationController.sourceView = button; //view the popover arrow points to...
}
/// then present popover...

Thread 1 signal SIGABRT

I am doing a project for CodeSchool which requires you to import information from the AFNetworking database. I have done all of that and there are no errors in my code, but when I debug it and click the ProfileViewController I get the Thread 1 signal SIGABRT.
Here is the code in the ProfileViewController.m:
#import "ProfileViewController.h"
#import "UIKit+AFNetworking/UIImageView+AFNetworking.h"
#interface ProfileViewController ()
#end
#implementation ProfileViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Profile";
self.tabBarItem.image = [UIImage imageNamed:#"tab_icon_profile"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.scrollView =[[UIScrollView alloc] initWithFrame:self.view.bounds];
self.scrollView.contentSize = CGSizeMake(320, 480);
self.scrollView.autoresizingMask = (UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleWidth);
self.view.backgroundColor = [UIColor darkGrayColor];
UIImageView *bigBirdView = [[UIImageView alloc] init];
bigBirdView.frame = CGRectMake(20, 20, 100, 114);
[bigBirdView setImageWithURL:[NSURL URLWithString:#"http://images3.wikia.nocookie.net/__cb20100901224145/muppet/images/f/f8/Big-bird-NEW.jpg"] placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
[self.scrollView addSubview:bigBirdView];
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 140, 280, 40)];
[nameLabel setBackgroundColor:[UIColor clearColor]];
[nameLabel setTextColor:[UIColor whiteColor]];
nameLabel.text = #"Name: Big Bird";
[self.scrollView addSubview:nameLabel];
UILabel *cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 200, 280, 40)];
[cityLabel setBackgroundColor:[UIColor clearColor]];
[cityLabel setTextColor:[UIColor whiteColor]];
cityLabel.text = #"From: Sesame Street";
[self.scrollView addSubview:cityLabel];
UITextView *biography= [[UITextView alloc] initWithFrame:CGRectMake(12, 260, 200, 200)];
[biography setBackgroundColor:[UIColor clearColor]];
biography.font = [UIFont fontWithName:#"Helvetica" size:15];
[biography setTextColor:[UIColor whiteColor]];
biography.editable = NO;
biography.text = #"Big Bird likes long walks on the beach, hanging with friends, and singing songs about various subjects. Big Bird is also really into organic bird seed.";
[self.scrollView addSubview:biography];
UILabel *memberSince = [[UILabel alloc] initWithFrame:CGRectMake(20, 400, 280, 40)];
[memberSince setBackgroundColor:[UIColor clearColor]];
[memberSince setTextColor:[UIColor whiteColor]];
memberSince.text = #"Member Since: 1969";
[self.scrollView addSubview:memberSince];
[self.view addSubview:self.scrollView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and here is the entire error, including the bt on the lldl:
(lldb) bt
* thread #1: tid = 0x28a71, 0x05b6fa6a libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread, stop reason = signal SIGABRT
frame #0: 0x05b6fa6a libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x05a2bb2f libsystem_c.dylib`pthread_kill + 101
frame #2: 0x057b2e12 libsystem_sim_c.dylib`abort + 127
frame #3: 0x055a69f9 libc++abi.dylib`abort_message + 105
frame #4: 0x055c76ab libc++abi.dylib`default_terminate_handler() + 292
frame #5: 0x014beb64 libobjc.A.dylib`_objc_terminate() + 108
frame #6: 0x055c4f60 libc++abi.dylib`std::__terminate(void (*)()) + 14
frame #7: 0x055c497d libc++abi.dylib`__cxa_throw + 116
frame #8: 0x014be9cd libobjc.A.dylib`objc_exception_throw + 323
frame #9: 0x023fd903 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 275
frame #10: 0x0235090b CoreFoundation`___forwarding___ + 1019
frame #11: 0x023504ee CoreFoundation`_CF_forwarding_prep_0 + 14
frame #12: 0x0000415c InstaPhoto`-[ProfileViewController viewDidLoad](self=0x0899ef40, _cmd=0x007b1d27) + 1260 at ProfileViewController.m:39
frame #13: 0x001379a8 UIKit`-[UIViewController loadViewIfRequired] + 696
frame #14: 0x0015d1a5 UIKit`-[UINavigationController _layoutViewController:] + 39
frame #15: 0x0015d6bb UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235
frame #16: 0x0015d7b3 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 78
frame #17: 0x0015e72c UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 645
frame #18: 0x0015f349 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 57
frame #19: 0x0029839d UIKit`-[UILayoutContainerView layoutSubviews] + 213
frame #20: 0x0008edd7 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
frame #21: 0x014d081f libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #22: 0x029fc72a QuartzCore`-[CALayer layoutSublayers] + 148
frame #23: 0x029f0514 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 380
frame #24: 0x029f0380 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
frame #25: 0x02958156 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294
frame #26: 0x029594e1 QuartzCore`CA::Transaction::commit() + 393
frame #27: 0x02a15870 QuartzCore`+[CATransaction flush] + 52
frame #28: 0x00040979 UIKit`_afterCACommitHandler + 131
frame #29: 0x0232853e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #30: 0x0232848f CoreFoundation`__CFRunLoopDoObservers + 399
frame #31: 0x023063b4 CoreFoundation`__CFRunLoopRun + 1076
frame #32: 0x02305b33 CoreFoundation`CFRunLoopRunSpecific + 467
frame #33: 0x0230594b CoreFoundation`CFRunLoopRunInMode + 123
frame #34: 0x022bc9d7 GraphicsServices`GSEventRunModal + 192
frame #35: 0x022bc7fe GraphicsServices`GSEventRun + 104
frame #36: 0x0002494b UIKit`UIApplicationMain + 1225
frame #37: 0x00001add InstaPhoto`main(argc=1, argv=0xbfffee84) + 141 at main.m:16
(lldb)
Your problem is at ProfileViewController.m line 39:
frame #12: 0x0000415c InstaPhoto`- [ProfileViewController viewDidLoad](self=0x0899ef40, _cmd=0x007b1d27) + 1260 at ProfileViewController.m:39
The doesNotRecognizeSelector exception being thrown:
frame #9: 0x023fd903 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 275
... indicates that an unimplemented method is being called.
I also suspect on following code,
UIImageView *bigBirdView = [[UIImageView alloc] init];
bigBirdView.frame = CGRectMake(20, 20, 100, 114);
[bigBirdView setImageWithURL:[NSURL URLWithString:#"http://images3.wikia.nocookie.net/__cb20100901224145/muppet/images/f/f8/Big-bird-NEW.jpg"] placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
[self.scrollView addSubview:bigBirdView];
1st)- their is not any method available in UIImageview like setImageWithURL:placeholderImage. Read documentation of UIImageview
2nd) - why you downloading image on main thread using following line,
[bigBirdView setImageWithURL:[NSURL URLWithString:#"http://images3.wikia.nocookie.net/__cb20100901224145/muppet/images/f/f8/Big-bird-NEW.jpg"] placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
download your image asynchronously using NSURLConnection delegate/block method yeah using GCD.

Blocks / dispatch_async: what is wrong with my simple code?

I tried to modify a simple CS193P iTunes U example/homework that just displays a UIImage inside a UIScrollView. I'm new to Obj-C blocks.
As soon as I try to wrap the line of code that downloads the Image inside a *dispatch_async* Block I break the zooming and get a
Uncaught exception: CALayer position contains NaN: [nan nan]
(showing the image and "scrolling" works, though)
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.activityIndicatorView startAnimating];
[self resetImage];
}
- (void)resetImage
{
if (self.detailItem && self.scrollView) {
//reset
self.scrollView.contentSize = CGSizeZero;
self.imageView.image = nil;
NSURL *imageURL = [FlickrFetcher urlForPhoto:self.detailItem format:FlickrPhotoFormatLarge];
__block NSData *imageData;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
dispatch_async(dispatch_get_main_queue(), ^{ //because of UI Stuff
UIImage *image = [[UIImage alloc] initWithData:imageData];
if (image) {
[self.activityIndicatorView stopAnimating];
[self.activityIndicatorView removeFromSuperview];
self.scrollView.zoomScale = 1.0;
self.scrollView.contentSize = image.size;
self.imageView.image = image;
CGRect frame = { CGPointZero , image.size };
self.imageView.frame = frame;
[self addToRecentPhotosList:self.detailItem];
NSLog(#"\n self.imageView.frame:%# \n self.imageView.bounds: %# \n self.scrollView.contentSize: %# \n self.scrollView.frame: %# \n self.scrollView.bounds: %# ", NSStringFromCGRect(self.imageView.frame), NSStringFromCGRect(self.imageView.bounds), NSStringFromCGSize(self.scrollView.contentSize), NSStringFromCGRect(self.scrollView.frame), NSStringFromCGRect(self.scrollView.bounds));
}
});
});
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.scrollView addSubview:self.imageView];
[self.scrollView addSubview:self.activityIndicatorView];
self.scrollView.minimumZoomScale = 0.2;
self.scrollView.maximumZoomScale = 5.0;
self.scrollView.delegate = self;
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (self.imageView.image) [self.scrollView zoomToRect:self.imageView.bounds animated:YES];
else self.activityIndicatorView.center = self.view.center;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
logged frames/bounds:
without dispatch_async blocks:
self.imageView.frame: {{0, 0}, {1024, 768}}
self.imageView.bounds: {{0, 0}, {1024, 768}}
with dispatch_async blocks:
self.imageView.frame: {{-7.62939e-06, -1.52588e-05}, {1024, 768}}
self.imageView.bounds: {{0, 0}, {204.8, 153.6}}
self.scrollView.contentSize: {1024, 768}
self.scrollView.frame: {{0, 0}, {320, 367}}
self.scrollView.bounds: {{0, 0}, {320, 367}}
Stack trace:
0 CoreFoundation 0x01ca002e __exceptionPreprocess + 206
1 libobjc.A.dylib 0x010dde7e objc_exception_throw + 44
2 CoreFoundation 0x01c9fdeb +[NSException raise:format:] + 139
3 QuartzCore 0x02293e0b _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 151
4 QuartzCore 0x0229eba1 -[CALayer(CALayerPrivate) setDoublePosition:] + 81
5 UIKit 0x000874a2 -[UIScrollView setZoomScale:withAnchorPoint:validatingScrollOffset:allowRubberbanding:animated:duration:notifyDelegate:force:] + 1476
6 UIKit 0x00083004 -[UIScrollView _updatePinchGestureForState:] + 3499
7 UIKit 0x00083960 -[UIScrollView handlePinch:] + 59
8 UIKit 0x002ec85a _UIGestureRecognizerSendActions + 139
9 UIKit 0x002eb99b -[UIGestureRecognizer _updateGestureWithEvent:] + 333
10 UIKit 0x002ed0df -[UIGestureRecognizer _delayedUpdateGesture] + 46
11 UIKit 0x002efd2d ___UIGestureRecognizerUpdate_block_invoke_0543 + 57
12 UIKit 0x002efcac _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 331
13 UIKit 0x002e7a28 _UIGestureRecognizerUpdate + 1348
14 UIKit 0x00054972 -[UIWindow _sendGesturesForEvent:] + 1283
15 UIKit 0x00054e53 -[UIWindow sendEvent:] + 98
16 UIKit 0x00032d4a -[UIApplication sendEvent:] + 436
17 UIKit 0x00024698 _UIApplicationHandleEvent + 9874
18 GraphicsServices 0x01bfbdf9 _PurpleEventCallback + 339
19 GraphicsServices 0x01bfbad0 PurpleEventCallback + 46
20 CoreFoundation 0x01c15bf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
21 CoreFoundation 0x01c15962 __CFRunLoopDoSource1 + 146
22 CoreFoundation 0x01c46bb6 __CFRunLoopRun + 2118
23 CoreFoundation 0x01c45f44 CFRunLoopRunSpecific + 276
24 CoreFoundation 0x01c45e1b CFRunLoopRunInMode + 123
25 GraphicsServices 0x01bfa7e3 GSEventRunModal + 88
26 GraphicsServices 0x01bfa668 GSEventRun + 104
27 UIKit 0x00021ffc UIApplicationMain + 1211
28 CS193P.4.SPoT 0x00002b84 main + 164
29 CS193P.4.SPoT 0x00002a95 start + 53
maybe, it'd be a good idea to synchronise threads each other first of all, if you want to use an object on a thread which is created on another thread. it would not be an award-winning idea to start to use the imageData before it is ready to use.
// ...
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_semaphore_t _semaphore = dispatch_semaphore_create(0);
imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
dispatch_semaphore_signal(_semaphore);
dispatch_async(dispatch_get_main_queue(), ^{ //because of UI Stuff
dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
dispatch_release(_semaphore);
UIImage *image = [[UIImage alloc] initWithData:imageData];
// etc...
};
};
// ...
UPDATE
try this solution as well, it works as well as the GCD version should have.
SPoTDetailViewController.h
#interface SPoTImageViewController : UIViewController <UISplitViewControllerDelegate, UIScrollViewDelegate> {
dispatch_semaphore_t _semaphore;
__block NSData *imageData;
}
// ...
#end
SPoTDetailViewController.m
- (void)resetImage
{
// Update the user interface for the detail item.
[self.activityIndicatorView startAnimating];
if (self.detailItem && self.scrollView) {
self.scrollView.contentSize = CGSizeZero;
self.imageView.image = nil;
[self performSelectorInBackground:#selector(downloadImageDataOnBackgroundThread) withObject:nil];
dispatch_semaphore_wait(_semaphore, DISPATCH_TIME_FOREVER);
// dispatch_release(_semaphore);
UIImage *image = [[UIImage alloc] initWithData:imageData];
if (image) {
[_activityIndicatorView stopAnimating];
_scrollView.zoomScale = 1.0;
_scrollView.contentSize = image.size;
_imageView.image = image;
CGRect frame = { CGPointZero , image.size };
NSLog(#"\n new CGRect frame:%# \n ", NSStringFromCGRect(frame));
_imageView.frame = frame;
NSLog(#"\n self.imageView.frame:%# \n self.imageView.bounds: %#", NSStringFromCGRect(self.imageView.frame), NSStringFromCGRect(self.imageView.bounds));
}
}
}
- (void)downloadImageDataOnBackgroundThread {
_semaphore = dispatch_semaphore_create(0);
NSURL *imageURL = [FlickrFetcher urlForPhoto:self.detailItem format:FlickrPhotoFormatLarge];
imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
dispatch_semaphore_signal(_semaphore);
}

TableView creates Zombie from ARC autorelease

I have a table inside of another table. I can add cells to both the "supertable" and "subtable" with no problem - they'll display, scroll, etc. However, when I try to interact with the "subtable" (select one of its textfields for editing) the program crashes. I ran the zombies tool on the program and it backtraced the crash to this code (I am using ARC):
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (saveTheTable == nil) saveTheTable = tableView;
static NSString *licenseCellId = #"licenseID";
UINib *nib = [UINib nibWithNibName:#"LicenseCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:licenseCellId];
//This line causes the crash
LicenseCell *cell = [tableView dequeueReusableCellWithIdentifier:licenseCellId];
cell.delegate = self;
[licenseFields replaceObjectAtIndex:indexPath.row withObject:cell];
return cell;
}
The responsible caller is the UITextField. It seems that the "subtable" is being dealloc'd by an autoreleasepool drain. Why would this be and how can I fix it? I tried storing strong references to the cells.
-Edit- Maybe the backtrace will help
* thread #1: tid = 0x1f03, 0x017a309b libobjc.A.dylib`objc_msgSend + 15, stop reason = EXC_BAD_ACCESS (code=2, address=0x8)
frame #0: 0x017a309b libobjc.A.dylib`objc_msgSend + 15
frame #1: 0x003c7c7e UIKit`-[UITextField canBecomeFirstResponder] + 167
frame #2: 0x00405fe7 UIKit`-[UIResponder becomeFirstResponder] + 179
frame #3: 0x005e58fb UIKit`-[UITextInteractionAssistant setFirstResponderIfNecessary] + 208
frame #4: 0x005e75f8 UIKit`-[UITextInteractionAssistant oneFingerTap:] + 1989
frame #5: 0x005dfe29 UIKit`_UIGestureRecognizerSendActions + 143
frame #6: 0x005df133 UIKit`-[UIGestureRecognizer _updateGestureWithEvent:] + 379
frame #7: 0x005e03bf UIKit`-[UIGestureRecognizer _delayedUpdateGesture] + 46
frame #8: 0x005e2a21 UIKit`___UIGestureRecognizerUpdate_block_invoke_0541 + 57
frame #9: 0x005e297c UIKit`_UIGestureRecognizerApplyBlocksToArray + 277
frame #10: 0x005db3d7 UIKit`_UIGestureRecognizerUpdate + 1026
frame #11: 0x003401a2 UIKit`-[UIWindow _sendGesturesForEvent:] + 1121
frame #12: 0x00340532 UIKit`-[UIWindow sendEvent:] + 93
frame #13: 0x00326dc4 UIKit`-[UIApplication sendEvent:] + 464
frame #14: 0x0031a634 UIKit`_UIApplicationHandleEvent + 8196
frame #15: 0x01f9aef5 GraphicsServices`PurpleEventCallback + 1274
frame #16: 0x012b3195 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
frame #17: 0x01217ff2 CoreFoundation`__CFRunLoopDoSource1 + 146
frame #18: 0x012168da CoreFoundation`__CFRunLoopRun + 2218
frame #19: 0x01215d84 CoreFoundation`CFRunLoopRunSpecific + 212
frame #20: 0x01215c9b CoreFoundation`CFRunLoopRunInMode + 123
frame #21: 0x01f997d8 GraphicsServices`GSEventRunModal + 190
frame #22: 0x01f9988a GraphicsServices`GSEventRun + 103
frame #23: 0x00318626 UIKit`UIApplicationMain + 1163
frame #24: 0x0000274d trainingAttendance`main + 141 at main.m:16
frame #25: 0x000026b5 trainingAttendance`start + 53
It turns out that, like phix23 said, the problem was with the registernib command. Here's the new cellForRowAtIndexPath method:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (saveTheTable == nil) saveTheTable = tableView;
static NSString *licenseCellId = #"licenseID";
LicenseCell *cell = (LicenseCell *)[tableView dequeueReusableCellWithIdentifier:licenseCellId];
if( cell == nil ) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"LicenseCell" owner:self options:nil];
cell = (LicenseCell *)[nib objectAtIndex:0];
}
cell.delegate = self;
[licenseFields replaceObjectAtIndex:indexPath.row withObject:cell];
if (nibRetainer == nil) nibRetainer = [[NSMutableArray alloc] initWithObjects:cell, nil];
else [nibRetainer addObject:cell];
return cell;
}