unrecognized selector sent to issue - iphone

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).

Related

App crashing when trying to implement UILongPressGesture

I'm trying to implement a UILongPressGesture on one of my tables in order to be able to reorder its cells. However, every time I long-press my app crashes.
Here's the file that implements the UILongPressGesture:
#import "LstrTableViewDragToMove.h"
#import "LstrTableViewCell.h"
#implementation LstrTableViewDragToMove
{
LstrTableView *_tableView;
BOOL _dragInProgress;
CGPoint _initialTouchPoint;
int _cellIndex;
LstrTableViewCell *_currentCell;
}
-(id)initWithTableView:(LstrTableView *)tableView
{
self = [super init];
if(self)
{
_tableView = tableView;
UIGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPress:)];
[_tableView addGestureRecognizer:recognizer];
}
return self;
}
-(BOOL) viewContainsPoint:(UIView*)view withPoint:(CGPoint)point {
CGRect frame = view.frame;
return (frame.origin.y < point.y) && (frame.origin.y + frame.size.height) > point.y;
}
-(void)handleLongPress:(UILongPressGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan) {
[self longPressStarted:recognizer];
}
if (recognizer.state == UIGestureRecognizerStateEnded) {
[self longPressEnded:recognizer];
}
}
-(void)longPressStarted:(UILongPressGestureRecognizer *)recognizer
{
NSLog(#"Started");
/*
_initialTouchPoint = [recognizer locationOfTouch:0 inView:_tableView.scrollView];
NSArray* visibleCells = _tableView.visibleCells;
for (int i=0; i < visibleCells.count; i++) {
UIView* cell = (UIView*)visibleCells[i];
if ([self viewContainsPoint:cell withPoint:_initialTouchPoint]) {
_cellIndex = i;
}
}
_currentCell = _tableView.visibleCells[_cellIndex];
_currentCell.label.allowsEditingTextAttributes = NO;
_currentCell.frame = CGRectMake(_currentCell.frame.origin.x, _currentCell.frame.origin.y, _currentCell.frame.size.width + 10.0f, _currentCell.frame.size.height + 10.0f);
[_currentCell addDropShadow];
*/
}
-(void)longPressEnded:(UILongPressGestureRecognizer *)recognizer
{
NSLog(#"Ended");
}
#end
And here's the error log:
2013-05-03 13:17:53.750 Lstr[19207:907] -[UILongPressGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x20856240
2013-05-03 13:17:53.754 Lstr[19207:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILongPressGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x20856240'
*** First throw call stack:
(0x3302a2a3 0x3ad5297f 0x3302de07 0x3302c531 0x3302d938 0x6db43 0x34f4f1ab 0x34f1863f 0x34f482a5 0x33941f53 0x32fff5df 0x32fff291 0x32ffdf01 0x32f70ebd 0x32f70d49 0x36b492eb 0x34e86301 0x66775 0x3b189b20)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Thanks in advance.
UPDATE:
Here's the method that has translationInView:
#pragma mark - horizontal pan gesture methods
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
CGPoint translation = [gestureRecognizer translationInView:[self superview]];
// Check for horizontal gesture
if (fabsf(translation.x) > fabsf(translation.y)) {
return YES;
}
return NO;
}
Are you using translationInView somewhere in your code?
You should change it to locationInView:
try and declare your tableview as a property in the header file
#property(nonatomic,retain)LstrTableView *_tableView;

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];

issue with UITapGestureRecognizer for a button

I've done the following thing:
buttonPlaylistView = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width *(urlList.count+1), 0, self.view.frame.size.width, self.view.frame.size.height)];
buttonPlaylistView.tag = 0;
UITapGestureRecognizer *doubleTap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTap:)];
[doubleTap3 setNumberOfTapsRequired:2];
[buttonPlaylistView addGestureRecognizer:doubleTap3];
[doubleTap3 release];
-(void) handleDoubleTap:(UITapGestureRecognizer *)sender{
if(sender.state == UIGestureRecognizerStateEnded)
int x = [sender tag];
return;
}
But I get SIGAGRT at this line: int x = [sender tag]; saying:
[UITapGestureRecognizer tag]: unrecognized selector sent to instance 0x61280b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITapGestureRecognizer tag]: unrecognized selector sent to instance 0x61280b0'
NOW:What's the problem and what's the solution for this?Thanks
-(void) handleDoubleTap:(UITapGestureRecognizer *)sender
{
if(sender.state == UIGestureRecognizerStateEnded)
{
int x = [sender.view tag];
}
}
Will fix the issue.
An UITapGestureRecognizer does not have a property named tag - as you see, the sender you get is NOT the button. You have to access the buttonPlayListView directly, like
int x = [buttonPlayListView tag];
or otherwise remember which button you want to access.
Even though I'm quite sure that you're going about this the wrong way, adding a double tap gesture recognizer to a UIButton, there is a way you can still perform the task you require that shouldn't be too much work for you.
You've made the comment
and how could I remember if I create let say 100 buttons
to one of the answers, the one which highlights what the issue is that's causing your SIGBART. UIGestureRecognizer does not have a tag property.
Here's what you could do, is to iterate through all the subviews of your [self view] and find the one that has the same UIGestureRecognizer, it's not the prettiest solution, and the more subview's you have the longer the loop will take. But it'll do what you seem to be looking for, so if you're adding .
In your handleDoubleTap function you could do the following
-(void) handleDoubleTap:(UITapGestureRecognizer *)sender
{
if(sender.state == UIGestureRecognizerStateEnded)
{
int iButtonTag = -1 //This is important later to escape the below for loop as we don't need to needlessly go around in circles
for(UIView* psubView in [[self view] subviews])
{
if( [psubView isKindOfClass:[UIButton class]] )
{
UIButton* pButton = (UIButton*)psubView;
for(UIGestureRecognizer* pGesture in [pButton gestureRecognizers] )
{
if( pGesture == sender )//this is the button we're after
{
iButtonTag = [pButton tag];
break;
}
}
if( iButton != -1 )//found what we came for
{
break;
}
}
}
//do what ever it was you needed to do now that you have the views tag, or you could have kept a reference to the button etc.
}
}
That should solve your problem. Alternatively if you're going to be adding buttons to subviews of subviews it would be better to keep track of your UIButtons in an NSMutableArray , you would do this by creating a class property (or member variable) and adding the buttons to this using the 'addObject:' function of NSMutableArray. Then instead of the line
for(UIView* psubView in [[self view] subviews])
above you could exchange that for
for( UIButton* pButton in m_pMutableButtonArray )
where "m_pMutableButtonArray" is the variable name you gave to your NSMutableArray you were storing the UIButtons in. This also means you would do away with the following if isKindOfClass test on the following line.
That should fix your problem.
Why are you putting a UITapGestureRecognizer in a button? The button already handles that for you and will send you a callback, you can add a target to a button using this UIControl method
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

What should be passed into a :(NSString *)text

Feeling a little confused. I am trying to pass a NSString as an argument to this method
-(void) setRightLabelText:(NSString *)text
{
rightLabel.text = text;
}
The code i use to call the method
for(int index=0; index<5; index++)
{
NSNumber *num = [card.statsArray objectAtIndex:index];
StatView *statView = (StatView *)[self.frontView viewWithTag:10+index];
NSString *nameHolder = #"test";
[statView setRightLabelText:nameHolder];
}
The code I used to create the View :
for(int i=0; i<totalButtons; i++)
{
StatView *sv = [[StatView alloc] initWithYPos:ypos];
sv.tag = 100 + i;
[sv.overlayButton addTarget:self action:#selector(statTapped:)
forControlEvents:UIControlEventTouchUpInside];
sv.overlayButton.tag = 10 + i;
[self.frontView addSubview:sv];
ypos += 26;
}
This to me looks perfect, but i get a crash when I get to this method call in the app.
Error Msg :
-[UIButton setRightLabelText:]: unrecognized selector sent to instance 0x5d116e0
2010-09-13 11:39:44.761 LeinsterRugby[1387:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton setRightLabelText:]: unrecognized selector sent to instance 0x5d116e0'
StatView *statView = (StatView *)[self.frontView viewWithTag:10+index]; returns an UIButton instead of a StatView because the tag matches the one you assign to the button with sv.overlayButton.tag = 10 + i;.
It looks as though you're sending the setRightLabelText message (selector) to an instance of UIButton rather than an object of the type that you're implementing.
Rather than:
[statView setRightLabelText:nameHolder];
Do you perhaps mean:
[self setRightLabelText:nameHolder];
Probable reason for the crash would be
StatView *statView = (StatView *)[self.frontView viewWithTag:10+index];
Your computation to get the StatView from (10+index) is wrong.
Calculate your index properly.

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

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.