What is wrong with my code? I'm using MBProgressHUD - iphone

I'm using MBProgress HUD and I don't know what is the problem.
I have a UIButton that shows the HUD.
This is my code:
- (void)showHUD:(id)sender {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
HUD.mode = MBProgressHUDModeCustomView;
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"No Internet Connection...";
HUD.opacity = 0.7;
HUD.customView =
[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image.png"]];
[HUD showWhileExecuting:#selector(hudWasHidden)
onTarget:self
withObject:nil
animated:YES];
}
- (void)hudWasHidden {
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
usleep(50000);
}
}
Here is the Console log:
2010-06-11 17:55:26.255 Dual Search[14166:207] * -[MBProgressHUD setCustomView:]:
unrecognized selector sent to instance 0x6321220 2010-06-11 17:55:26.256 Dual
Search[14166:207] Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '** -[MBProgressHUD setCustomView:]:
unrecognized selector sent to instance 0x6321220' 2010-06-11 17:55:26.256 Dual
Search[14166:207] Stack: ( 41853515, 2505499913, 42125115, 41587990, 41584658,
13036, 2853830, 3324117, 3332879, 3328066, 2977128, 2871789, 2903111, 49860988,
41394236, 41390152, 49854621, 49854818, 2895329, 10508, 10362 )
My app always crashes when clicking the UIButton.
Thanks

This is a common crash in Cocoa code: "unrecognized selector" is very explicit in this case. MBProgressHUD doesn't have a customView property, and attempting to set it is causing the crash. The setCustomView is the implicit selector (method) being called here, and Objective-C will crash when a called method isn't there.
Not sure what to tell you about how to accomplish what you're trying to do.

Related

How to create raw image in iOS?

I want to create raw image using UIImagePickerController. I'm doing like this but getting crash on this line uiipc.mediaTypes=#[(NSString *)kUTTypeRawImage]; crash report says:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'No available types for source 1'.
Code here
UIImagePickerController *uiipc = [[UIImagePickerController alloc] init];
uiipc.delegate=self;
uiipc.mediaTypes=[UIImagePickerController availableMediaTypesForSourceType:uiipc.sourceType];
// uiipc.mediaTypes = #[(NSString *)kUTTypeImage];
uiipc.mediaTypes=#[(NSString *)kUTTypeRawImage];// Getting crash here
uiipc.sourceType = UIImagePickerControllerSourceTypeCamera;
uiipc.allowsEditing = YES;
_imgPickViewController=uiipc;
[self presentViewController:_imgPickViewController animated:NO completion:nil];

How to find what kind of parameters is required for undocumented version of handleGesture selector (for UIWebView)?

I have added a custom popup menu to UIWebView instance:
- (void)viewDidLoad
{
UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:#selector(handleGesture::)] autorelease];
}
- (void)handleGesture
{
}
- (void)handleGesture:(UIGestureRecognizer*)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
[gestureRecognizer.view becomeFirstResponder];
UIMenuController* mc = [UIMenuController sharedMenuController];
[mc setTargetRect: gestureRecognizer.view.frame inView: gestureRecognizer.view.superview];
[mc setMenuVisible: YES animated: YES];
}
And it works! Until I focus textarea (CodeMirror editor) on a webpage. At this case I have the following exception:
-[FirstViewController handleGesture::]: unrecognized selector sent to instance 0x20369c00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController handleGesture::]: unrecognized selector sent to instance 0x20369c00'
*** First throw call stack:
(0x3608c2a3 0x3439c97f 0x3608fe07 0x3608e531 0x35fe5f68 0x3747ad31 0x374423dd 0x3762f479 0x37366837 0x3736529b 0x360616cd 0x3605f9c1 0x3605fd17 0x35fd2ebd 0x35fd2d49 0x3650f2eb 0x373b1301 0x140bb 0x14060)
libc++abi.dylib: terminate called throwing an exception
(lldb)
I think it's required to implement undocumented version of handleGesture selector with exotic parameters. Is it right? How to find what kind of parameters is required?
The correct code:
initWithTarget:self action:#selector(handleGesture:)] autorelease];

unrecognized selector sent to issue

I am getting the following error:
- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] init];
label = [[UILabel alloc] initWithFrame:view.bounds];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [label.font fontWithSize:50.0f];
[view addSubview:label];
}
else
{
label = [[view subviews] lastObject];
}
//set label
label.text = (index == 0)? #"[": #"]";
return view;
}
-[SocialCatalogViewController carousel:placeholderViewAtIndex:]: unrecognized selector sent to instance 0x1296db80
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SocialCatalogViewController carousel:placeholderViewAtIndex:]: unrecognized selector sent to instance 0x1296db80'
*** First throw call stack:
(0x2f3c052 0x30cdd0a 0x2f3dced 0x2f3e083 0x2ea30c9 0x2ea2ce2 0x2f1b25 0x2f1e6c 0x2f25b3 0x2f5863 0x2f1a44 0x2f2a50 0x2edd77 0x352e4b 0x143664e 0x1436941 0x144847d 0x144866f 0x144893b 0x14493df 0x1449986 0x14495a4 0x2e01b9 0x2ea1d4 0x2f3dec9 0x13735c2 0x137355a 0x1418b76 0x141903f 0x14182fe 0x1631a2a 0x2f109ce 0x2ea7670 0x2e734f6 0x2e72db4 0x2e72ccb 0x3349879 0x334993e 0x1370a9b 0x2e06 0x2d75 0x1)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
Any idea?
Well, yes. The error indicates you're passing two parameters (for carousel and placeholderViewAtIndex). However, the method is actually carousel: placeholderViewAtIndex: reusingView:, i.e. taking three parameters. So, just pass one more for reusingView (or nil, as the method has logic to handle this case).

I am currently getting this crash log in the console:

2011-12-01 18:10:36.932 AVCam[3987:17903] *** -[UIImage _isResizable]: message sent to deallocated instance 0xdf7e360
Current language: auto; currently objective-c
The Code is
UIImageView * firstView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
[firstView setContentMode:UIViewContentModeScaleAspectFill];
firstView.image = firstPhoto.photo;
[firstBlock addSubview:firstView];
[firstView release];
Does anyone know what this means? What could be the cause of it?
Thanks!
The problem should be here:
firstView.image = firstPhoto.photo;
What is firstPhoto? When does it get released? I guess it gets deallocated before it becomes the content of that UIImageView.
You'll probably have to send a `[retain]` message, something like:
firstView.image = [firstPhoto.photo retain];

UIImagePickerController crashes on iOS4

When trying to show the UIImagePickerController I had strange problems with my app crashing on iOS4. Here's the output from log:
malloc: *** error for object 0x550ba20: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Setting breakpoints, trying to spy the name of the object 0x550ba20 (with print-object) does not work. Enabling zombie detection also does not work. Here is my code:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
cameraPicker = [[UIImagePickerController alloc] init];
cameraPicker.delegate = self;
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Insert the overlay:
cameraPicker.cameraOverlayView = self.overlay;
self.cameraPicker.delegate = self;
//Hide controls
cameraPicker.showsCameraControls = NO;
cameraPicker.navigationBarHidden = YES;
// Make camera view full screen:
cameraPicker.wantsFullScreenLayout = YES;
cameraPicker.cameraViewTransform = CGAffineTransformScale(self.cameraPicker.cameraViewTransform, 1.0, 1.12412);
[self presentModalViewController:cameraPicker animated:NO];
[cameraPicker release];
Any ideas? Code is executed at the very end of viewDidLoad.
Is cameraPicker a property? You are initializing it first as a local variable and then using it as a property:
cameraPicker.cameraOverlayView = self.overlay;
!!self.!!cameraPicker.delegate = self;
and
cameraPicker.cameraViewTransform = CGAffineTransformScale(!!self.!!cameraPicker.cameraViewTransform, 1.0, 1.12412);