UIButton created in UItableview cell crashes when tapped - iphone

I created a custom UItableviewcell
added a button into its initWithStyle area:
favoriteButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
favoriteButton.backgroundColor = [UIColor clearColor];
[favoriteButton setTitle:#"Play" forState:UIControlStateNormal];
[favoriteButton addTarget:self action:#selector(favoriteClick:) forControlEvents:UIControlEventTouchUpInside];
favoriteButton.center = self.center;
set its frame and layout in:
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame = CGRectMake(boundsX+200, 44, 40, 40);
favoriteButton.frame = frame;
}
and then in my tableviewcontroller.m file I use that tableviewcell and have the user click tap to go to the action within that tableviewcontroller.m code
-(void)favoriteClick:(id)sender// forEvent:(UIEvent*)event
{
NSLog(#"click");
}
however when i tap the button I get an unhandled exception:
2010-07-24 16:06:02.197 Film Fest[10342:40b] -[ProgramGuideCell favoriteClick:]: unrecognized selector sent to instance 0x6e63ff0
2010-07-24 16:06:02.200 Film Fest[10342:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ProgramGuideCell favoriteClick:]: unrecognized selector sent to instance 0x6e63ff0'
*** Call stack at first throw:
(
0 CoreFoundation 0x02a56919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02ba45de objc_exception_throw + 47
2 CoreFoundation 0x02a5842b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x029c8116 ___forwarding___ + 966
4 CoreFoundation 0x029c7cd2 _CF_forwarding_prep_0 + 50
5 UIKit 0x00301e14 -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x0038b6c8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0038db4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x0038c6f7 -[UIControl touchesEnded:withEvent:] + 458
9 UIKit 0x00579070 _UIGestureRecognizerUpdateObserver + 3687
10 CoreFoundation 0x02a37d1b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
11 CoreFoundation 0x029cc987 __CFRunLoopDoObservers + 295
12 CoreFoundation 0x02995c17 __CFRunLoopRun + 1575
13 CoreFoundation 0x02995280 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x029951a1 CFRunLoopRunInMode + 97
15 GraphicsServices 0x030b42c8 GSEventRunModal + 217
16 GraphicsServices 0x030b438d GSEventRun + 115
17 UIKit 0x0030fb58 UIApplicationMain + 1160
18 Film Fest 0x00002170 main + 102
19 Film Fest 0x00002101 start + 53
)
terminate called after throwing an instance of 'NSException'
I dont see what Im doing wrong here...

Try returning IBAction instead of void on your selector, and put the selector in the ProgramGuideCell instead of tableviewcontroller.
-(IBAction)favoriteClick:(id)sender// forEvent:(UIEvent*)event
{
NSLog(#"click");
}

Related

webcore crash in UIWebView's init method

I have run into some kind of crash, here is the crash stack:
WebCore 0x353c81b4 WebCore::PageCache::markPagesForFullStyleRecalc(WebCore::Page*) + 20
WebKit 0x36a6a45f -[WebView(WebPrivate) _initWithFrame:frameName:groupName:usesDocumentViews:] + 139
WebKit 0x36a6a3cd -[WebView initWithFrame:frameName:groupName:] + 53
WebKit 0x36a6a393 -[WebView initWithFrame:] + 47
UIKit 0x37251bfb -[UIWebDocumentView initWithWebView:frame:] + 287
UIKit 0x372828d1 -[UIWebBrowserView initWithWebView:frame:] + 57
UIKit 0x37282891 -[UIWebDocumentView initWithFrame:] + 41
UIKit 0x37282809 -[UIWebBrowserView initWithFrame:] + 49
UIKit 0x37437d73 -[UIWebView _webViewCommonInitWithWebView:scalesPageToFit:shouldEnableReachability:] + 235
UIKit 0x374385a9 -[UIWebView initWithFrame:] + 81
SeMob 0x001c216d -[SeMobWebInternalView initWithFrame:] (SeMobWebInternalView.m:64)
SeMob 0x001e7761 -[SeMobWebReader prepareReaderInWebView:] (SeMobWebReader.m:102)
SeMob 0x000eeb0d -[SeMobWebView webViewDidFinishLoad:] (SeMobWebView.m:1475)
CoreFoundation 0x346979c4 __invoking___ + 68
CoreFoundation 0x345eefeb -[NSInvocation invoke] + 287
CoreFoundation 0x345eeb43 -[NSInvocation invokeWithTarget:] + 51
WebKit 0x36a6189b -[_WebSafeForwarder forwardInvocation:] + 375
CoreFoundation 0x3469661b ___forwarding___ + 627
CoreFoundation 0x345edf68 __forwarding_prep_0___ + 24
CoreFoundation 0x346979c4 __invoking___ + 68
CoreFoundation 0x345eefeb -[NSInvocation invoke] + 287
WebCore 0x354197eb _ZL11SendMessageP12NSInvocation + 27
WebCore 0x35456fa5 _ZL20HandleDelegateSourcePv + 81
CoreFoundation 0x34669683 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
CoreFoundation 0x34668ee9 __CFRunLoopDoSources0 + 213
CoreFoundation 0x34667cb7 __CFRunLoopRun + 647
CoreFoundation 0x345daebd CFRunLoopRunSpecific + 357
CoreFoundation 0x345dad49 CFRunLoopRunInMode + 105
GraphicsServices 0x353432eb GSEventRunModal + 75
UIKit 0x37220301 UIApplicationMain + 1121
SeMob 0x000d48a7 main (main.m:12)
and two pieces of code:
- (void)prepareReaderInWebView:(UIWebView *)webView
{
// ...omit some code here
if ([readableContent length]) {
self.innerWebView = [[[SeMobWebInternalView alloc] initWithFrame:webView.bounds] autorelease];
innerWebView.scalesPageToFit = NO;
innerWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
innerWebView.scrollView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
innerWebView.scrollView.scrollsToTop = YES;
innerWebView.delegate = self;
...
}
#interface SeMobWebInternalView : UIWebView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIMenuItem *flag =
[[UIMenuItem alloc] initWithTitle:#"search" action:#selector(search:)];
...
}
the crash always occers in the super's init method. Why it always crash? Plz help me !
Apple documentation says that UIWebView should not be subclassed:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006950-CH3-DontLinkElementID_2
Check subclassing notes.
As #cosmin stated your not meant to subclass UIWebView, from your code it looks like your trying to customize the appearance. try this code instead:
webView.backgroundColor = [UIColor clearColor]; // changes to clear colour
webView.opaque = NO;
for(UIView *innerView in [[[webView subviews] objectAtIndex:0] subviews]) { // Hide images that make shadow
if ([innerView isKindOfClass:[UIImageView class]]) {
innerView.hidden = YES;
}
}

How call customview on action of button?

I have create a demo project in which i have add button. On button action i am calling a custom view. On that custom view i have add a picker view, a toolbar and bar button. On action of button i am calling that custom view. I have used this code...
-(IBAction)Picker{
mpv_object = [[MyPickerView alloc] initWithNibName:#"MyPickerView" bundle:nil];
[self.view addSubview:mpv_object];
[mpv_object release];
}
But i give error which i given below...
2011-09-26 09:49:00.236 Web[440:207] -[MyPickerView initWithNibName:bundle:]: unrecognized selector sent to instance 0x4b4dcb0
2011-09-26 09:49:00.287 Web[440:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyPickerView initWithNibName:bundle:]: unrecognized selector sent to instance 0x4b4dcb0'
* Call stack at first throw:
(
0 CoreFoundation 0x00daebe9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f035c2 objc_exception_throw + 47
2 CoreFoundation 0x00db06fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d20366 __forwarding + 966
4 CoreFoundation 0x00d1ff22 _CF_forwarding_prep_0 + 50
5 Web 0x0000223a -[WebViewController Picker] + 102
6 UIKit 0x002b7a6e -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x003461b5 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x00348647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9 UIKit 0x003471f4 -[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x002dc0d1 -[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x002bd37a -[UIApplication sendEvent:] + 447
12 UIKit 0x002c2732 _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x016e4a36 PurpleEventCallback + 1550
14 CoreFoundation 0x00d90064 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
15 CoreFoundation 0x00cf06f7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00ced983 __CFRunLoopRun + 979
17 CoreFoundation 0x00ced240 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00ced161 CFRunLoopRunInMode + 97
19 GraphicsServices 0x016e3268 GSEventRunModal + 217
20 GraphicsServices 0x016e332d GSEventRun + 115
21 UIKit 0x002c642e UIApplicationMain + 1160
22 Web 0x00001f80 main + 102
23 Web 0x00001f11 start + 53
)
terminate called after throwing an instance of 'NSException'
What is error in this?
It sounds like MyPickerView is a UIView subclass. initWithNibName:bundle is not a method that exists on UIView subclasses. It is a method that exists on UIViewController subclasses. That is what the error message means.
unrecognized selector sent to instance suggests that MyPickerView's superclass doesn't know what initWithNibName:bundle is, which is because UIView doesn't know that method (it exists in UIViewController).
Right way to do this would be something like this
UIView *dpView;
NSArray *nibViews;
nibViews = [[NSBundle mainBundle] loadNibNamed:#"DatePickerSliderViewNew" owner:self options:nil];
dpView = [ nibViews objectAtIndex: 0];
int outside = CGRectGetMaxY(self.view.bounds);
dpView.frame = CGRectMake(0, outside, 320, 260);
[self.view addSubview:dpView];
[UIView beginAnimations:nil context:nil];
dpView.frame = CGRectMake(0, outside - 260, 320, 260);
[UIView commitAnimations];

Exception thrown by code: Stack trace shows this is the last functioncall made: [UIControl(Deprecated)sendAction:toTarget:forEvent]

Here is the code:
- (IBAction)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(#"Inside textfieldDidBeginEditing");
textFieldBeingEdited = textField;
}
//==============================================================================
-(IBAction)textFieldDoneEditing:(id)sender
{
textFieldBeingEdited = NULL;
[sender resignFirstResponder];
if (moveViewUp)
{
[self scrollTheView:NO];
}
}
//==============================================================================
-(void)keyboardWillShow:(NSNotification *)notif
{
NSLog(#"Inside keyborad will show");
NSDictionary *info = [notif userInfo];
NSValue *aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
float bottomPoint = (textFieldBeingEdited.frame.origin.y + textFieldBeingEdited.frame.size.height /*+ 20*/);
scrollAmount = keyboardSize.height - (self.view.frame.size.height- bottomPoint);
if(scrollAmount > 0)
{
moveViewUp = YES;
[self scrollTheView:YES];
}
else
{
moveViewUp = NO;
}
}
Here is the screen shot of the view controller
when I tap on any one of these text fields. An exception is thrown
-[__NSCFType textFieldDidBeginEditing:]: unrecognized selector sent to instance 0x5a3c100
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType textFieldDidBeginEditing:]: unrecognized selector sent to instance 0x5a3c100'
*** Call stack at first throw:
(
0 CoreFoundation 0x010275a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0117b313 objc_exception_throw + 44
2 CoreFoundation 0x010290bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00f98966 ___forwarding___ + 966
4 CoreFoundation 0x00f98522 _CF_forwarding_prep_0 + 50
5 UIKit 0x003a1581 -[UIControl(Deprecated) sendAction:toTarget:forEvent:] + 67
6 UIKit 0x003a3e62 -[UIControl(Internal) _sendActionsForEventMask:withEvent:] + 525
7 UIKit 0x003a9e11 -[UITextField willAttachFieldEditor:] + 404
8 UIKit 0x003bbcdf -[UIFieldEditor becomeFieldEditorForView:] + 653
9 UIKit 0x003abf98 -[UITextField _becomeFirstResponder] + 99
10 UIKit 0x003e02c3 -[UIResponder becomeFirstResponder] + 328
11 UIKit 0x005a8961 -[UITextInteractionAssistant setFirstResponderIfNecessary] + 208
12 UIKit 0x005ab5e2 -[UITextInteractionAssistant oneFingerTap:] + 1676
13 UIKit 0x005a24f2 -[UIGestureRecognizer _updateGestureWithEvent:] + 730
14 UIKit 0x0059e4fe -[UIGestureRecognizer _delayedUpdateGesture] + 47
15 UIKit 0x005a4afc _UIGestureRecognizerUpdateObserver + 584
16 UIKit 0x005a4ce1 _UIGestureRecognizerUpdateGesturesFromSendEvent + 51
17 UIKit 0x0033832a -[UIWindow _sendGesturesForEvent:] + 1292
18 UIKit 0x00333ca3 -[UIWindow sendEvent:] + 105
19 UIKit 0x00316c37 -[UIApplication sendEvent:] + 447
20 UIKit 0x0031bf2e _UIApplicationHandleEvent + 7576
21 GraphicsServices 0x0197f992 PurpleEventCallback + 1550
22 CoreFoundation 0x01008944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
23 CoreFoundation 0x00f68cf7 __CFRunLoopDoSource1 + 215
24 CoreFoundation 0x00f65f83 __CFRunLoopRun + 979
25 CoreFoundation 0x00f65840 CFRunLoopRunSpecific + 208
26 CoreFoundation 0x00f65761 CFRunLoopRunInMode + 97
27 GraphicsServices 0x0197e1c4 GSEventRunModal + 217
28 GraphicsServices 0x0197e289 GSEventRun + 115
29 UIKit 0x0031fc93 UIApplicationMain + 1160
terminate called after throwing an instance of 'NSException'
please help
Shouldn't the method signature be:
-(void)textFieldDidBeginEditing:(UITextField *)textField
i.e. (void) instead of (IBAction)

Application Crashes on [scrollView removeFromSuperview];

Hell All,
I am new to iPhone and struggling with following problem.
When i remove scroll view with following statement my appli crashes.
[scrollView removeFromSuperview];
I am adding uiscrollview with following line.
[self.view addSubview:scrollView];
Hereis the log.
Thread 0 Crashed:
0 libobjc.A.dylib 0x34a80466 objc_msgSend + 18
1 UIKit 0x341aaaa8 -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 152
2 UIKit 0x341aaace -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 190
3 UIKit 0x341aaace -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 190
4 UIKit 0x341c05a0 -[UIView(Hierarchy) removeFromSuperview] + 208
5 UIKit 0x34249a76 -[UIScrollView removeFromSuperview] + 42
6 KabushikiShimbun 0x000387b6 -[PDFPageScrollViewController ReGenerateScrollViewAsperNewData] (PDFPageScrollViewController.m:1451)
7 KabushikiShimbun 0x00038aac -[PDFPageScrollViewController CheckPageUpdationWithDate:] (PDFPageScrollViewController.m:1441)
8 KabushikiShimbun 0x0003c472 -[PDFPageScrollViewController requestFinished:] (PDFPageScrollViewController.m:792)
9 CoreFoundation 0x35818bb8 -[NSObject(NSObject) performSelector:withObject:] + 16
10 KabushikiShimbun 0x0000e9ba -[ASIHTTPRequest reportFinished] (ASIHTTPRequest.m:1945)
11 CoreFoundation 0x35818bb8 -[NSObject(NSObject) performSelector:withObject:] + 16
12 Foundation 0x3118178e __NSThreadPerformPerform + 262
13 CoreFoundation 0x358307d6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
14 CoreFoundation 0x358025b0 __CFRunLoopDoSources0 + 376
15 CoreFoundation 0x35801e54 __CFRunLoopRun + 224
16 CoreFoundation 0x35801c80 CFRunLoopRunSpecific + 224
17 CoreFoundation 0x35801b88 CFRunLoopRunInMode + 52
18 GraphicsServices 0x320c84a4 GSEventRunModal + 108
19 GraphicsServices 0x320c8550 GSEventRun + 56
20 UIKit 0x341dc322 -[UIApplication _run] + 406
21 UIKit 0x341d9e8c UIApplicationMain + 664
22 KabushikiShimbun 0x00002da6 main (main.m:14)
23 KabushikiShimbun 0x00002d70 start + 32
Any Idea ?
Thank you.
Check whether it has a superview before removing from superview;
if([scrollView superview]!=nil){
[scrollView removeFromSuperview];
}
Try this code
for(UIView *view in self.view.subviews)
{
if([view isMemberOfClass:[UIScrollView class]])
{
[scrollview removeFromSuperView];
}
}
Try this code. It's tested.
NSArray *subviews = [[NSArray alloc] initWithArray:self.view.subviews];
for(UIScrollView *subview in subviews) {
[subview removeFromSuperView];
}
[subviews release];
but be carefull it removes all ScrollViews present in your self.view

UIButton in UITableViewCell crashes when clicked

This should be simple, but I can't figure out what's wrong. I'm creating a tableview and I want a button that I can click to switch between checked and unchecked:
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:DiaperCellIdentifier];
if (cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:DiaperCellIdentifier] autorelease];
wetButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
image = [UIImage imageNamed:#"unchecked_large.png"];
CGRect frame = CGRectMake(150.0, 5.0, image.size.width, image.size.height);
wetButton.frame = frame;
[wetButton setBackgroundImage:image forState:UIControlStateNormal];
[wetButton addTarget:self action:#selector(wetClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:wetButton];
Now when I click this button, I get a stack trace....[NSCFString scale]: unrecognized selector sent to instance.... thanks for any help.
- (void) wetClicked:(id)sender{
if (isWet) {
isWet = NO;
[wetButton setBackgroundImage:#"unchecked_large.png" forState:UIControlStateNormal];
} else {
isWet = YES;
[wetButton setBackgroundImage:#"checked_large.png" forState:UIControlStateNormal];
}
}
and here's the trace:
2011-03-09 10:19:57.124 InfantCare[64064:207] -[NSCFString scale]: unrecognized selector sent to instance 0x33be0
2011-03-09 10:19:57.240 InfantCare[64064:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString scale]: unrecognized selector sent to instance 0x33be0'
* Call stack at first throw:
(
0 CoreFoundation 0x00f2dbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010825c2 objc_exception_throw + 47
2 CoreFoundation 0x00f2f6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00e9f366 ___forwarding___ + 966
4 CoreFoundation 0x00e9ef22 _CF_forwarding_prep_0 + 50
5 UIKit 0x003d1e7b -[UIImageView setImage:] + 250
6 UIKit 0x004ea353 -[UIButton layoutSubviews] + 273
7 QuartzCore 0x01d58451 -[CALayer layoutSublayers] + 181
8 QuartzCore 0x01d5817c CALayerLayoutIfNeeded + 220
9 QuartzCore 0x01d5137c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
10 QuartzCore 0x01d510d0 _ZN2CA11Transaction6commitEv + 292
11 QuartzCore 0x01d817d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
12 CoreFoundation 0x00f0efbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
13 CoreFoundation 0x00ea40e7 __CFRunLoopDoObservers + 295
14 CoreFoundation 0x00e6cbd7 __CFRunLoopRun + 1575
15 CoreFoundation 0x00e6c240 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00e6c161 CFRunLoopRunInMode + 97
17 GraphicsServices 0x017cf268 GSEventRunModal + 217
18 GraphicsServices 0x017cf32d GSEventRun + 115
19 UIKit 0x0031642e UIApplicationMain + 1160
20 InfantCare 0x00002228 main + 102
21 InfantCare 0x000021b9 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
I think you need to use an UIImage instance as a parameter when you call the function setBackgroundImage:
[wetButton setBackgroundImage:#"unchecked_large.png" forState:UIControlStateNormal];
use instead:
[wetButton setBackgroundImage:[UIImage imageNamed:#"unchecked_large.png"] forState:UIControlStateNormal];
The code you have posted is fine. The problem is most likely in your wetClicked: method, you are calling the scale method on an NSString.
Now that you've posted wetClicked: and the trace, I see the problem: You're passing a string instead of an image to setBackgroundImage:forState:. Try this instead:
- (void) wetClicked:(id)sender{
if (isWet) {
isWet = NO;
[wetButton setBackgroundImage:[UIImage imageNamed:#"unchecked_large.png"] forState:UIControlStateNormal];
} else {
isWet = YES;
[wetButton setBackgroundImage:[UIImage imageNamed:#"checked_large.png"] forState:UIControlStateNormal];
}
}