Reputation: 254
My application crashes and showing the error below.
Thread 0 Crashed:
0 libobjc.A.dylib 0x3b5d7b26 objc_msgSend + 6
1 UIKit 0x339c74f4 -[UIResponder(Static) _setFirstResponder:] + 40
2 UIKit 0x339c74f4 -[UIResponder(Static) _setFirstResponder:] + 40
3 UIKit 0x339b3000 -[UIResponder resignFirstResponder] + 248
4 UIKit 0x339e4e9c -[UITableView reloadData] + 224
5 CSModule 0x001588e2 -[UIBubbleTableView reloadData]
I try to fix issue but did not get solution. Please help me to fix the issue.
I am have created a custom view with a label to on table cellview, when we tap on that custom view , it show a UIMenuController with copy option. My custom view handle tap gesture as below
-(void) handleTapGesture:(UIGestureRecognizer*) recognizer{
if (self.window == nil) {
NSLog(@" \n\n\n\n Window is null \n\n\n\n\n\n");
return;
}
[self becomeFirstResponder];
CGRect targetRectangle = CGRectMake(self.bounds.size.width/2, 2, 2, 2);
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setTargetRect:targetRectangle inView:self];
[menuController setMenuVisible:YES animated:YES];
}
If I did not handle tap gesture and do not show this UIMenuController , then it does not produce any crashes.
Crashes occurs randomly , I have implement Pull to refresh in UITableView, on pull I download previous data from server and reload tableview, at the same time I tap on the custom view in cell, some time crashes occurs.
One more thing some time crashes occurs at handleTapGesture function as bellow.
Thread 0 Crashed:
0 libobjc.A.dylib 0x3b5d7b26 objc_msgSend + 6
1 UIKit 0x339c74f4 -[UIResponder(Static) _setFirstResponder:] + 40
2 UIKit 0x339c74f4 -[UIResponder(Static) _setFirstResponder:] + 40
3 UIKit 0x339c74f4 -[UIResponder(Static) _setFirstResponder:] + 40
4 UIKit 0x339b2f92 -[UIResponder resignFirstResponder] + 138
5 UIKit 0x3398d958 -[UIResponder becomeFirstResponder] + 308
6 UIKit 0x3398dc46 -[UIView(Hierarchy) becomeFirstResponder] + 102
7 CSModule 0x0006ceb2 -[UIChatFootageTextView handleTapGesture:]
Please If you have any idea to fix the issue , then please help me to fix it.
Upvotes: 0
Views: 1370
Reputation: 254
Previously, I was getting the crash issue. As per my idea, since I was setting my custom view as first responder to show UIMenuController, that was required to visible UIMenuController. So I can't remove that statement.
To fix this, I resign to it as first responder just after the UIMenuController set as visible. Now my application does not get that random crashes.
-(void) handleTapGesture:(UIGestureRecognizer*) recognizer{
if (self.window == nil) {
NSLog(@" \n\n\n\n Window is null \n\n\n\n\n\n");
return;
}
[self becomeFirstResponder];
CGRect targetRectangle = CGRectMake(self.bounds.size.width/2, 2, 2, 2);
UIMenuController *menuController = [UIMenuController sharedMenuController];
[menuController setTargetRect:targetRectangle inView:self];
[menuController setMenuVisible:YES animated:YES];
[self resignFirstResponder];
}
Upvotes: 1
Reputation: 1722
FWIW, I noticed this same issue with my apps on ios8 GM. The problem seems to be that if you call reloadData on a UITableView that has no records to display (I.E newly installed app) it crashes.
I had to start checking to make sure that the number of records I was trying to display was >0 before calling the method... Personally I think this is a bug in ios8. If I ask a view to reloaddata, and there is no data, it should handle it. I should not have to evaluate the data existence before asking a view to reload.. kind of breaks the whole MVC design patterns IMO.
good luck to you all.
Upvotes: 2
Reputation: 5230
The UILabel
does not allow becomeFirstResponder
. You have to subclass the UILabel
to achieve this.
@interface CustomLabel : UILabel
@end
@implementation CustomLabel
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
return (action == @selector(copy:));
}
- (void)copy:(id)sender {
[[UIPasteboard generalPasteboard] setString:self.text];
}
@end
Use this custom label and add your gesture to this.
Upvotes: 0