Why this code no longer work in 7.1? - objective-c

UITextField * textField= self.textField;
textField.background = [UIImage resizeableImageWithCapInsets2:UIEdgeInsetsMake(0, 7, 0, 7) withName:#"Search-Field"];
Simple code.
2014-03-13 09:31:02.099 isikota[179:60b] -[BGSearchBar setBackground:]: unrecognized selector sent to instance 0x17566b20
2014-03-13 09:32:17.720 isikota[179:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BGSearchBar setBackground:]: unrecognized selector sent to instance 0x17566b20'
It doesn't make sense. Clearly background is a property of textField
I found out that the problem is I use this:
-(UITextField *) textField
{
UIView * textFieldView = [self findASubViewWithProtocol:#protocol(UITextInputTraits)];
return (UITextField *)textFieldView;
}
This seems to be no longer the way to get a textField from UISearchBar. How to do so then?
I think the problem is since 7.1 [UISearchBar conforms to UITextInputTraits]
Also I wonder why
return (UITextField *)textFieldView;
doesn't return a run time error because now textFieldView is no longer a subclass of UITextField

I've always done it like this:
for (UIView* v in self.searchbar.subviews) {
if ([v isKindOfClass: [UITextField class]]) {
return v;
}
}
Or, in iOS 7:
for (UIView* v in [self.searchbar.subviews[0] subviews]) {
if ([v isKindOfClass: [UITextField class]]) {
return v;
}
}
Does that not work any more?

Related

Unusual crash with cocoa webView -elementAtPoint: (OS X)

I have a subclass of webView that overrides - hitTest: The basic idea is that I want clicks on the webView to pass through to the nextResponder if the click was on the body DOM element. The method looks like this
- (NSView *)hitTest:(NSPoint)aPoint
{
NSDictionary *dict = [self elementAtPoint:aPoint];
if([[dict valueForKey:#"WebElementDOMNode"] isKindOfClass:[DOMHTMLBodyElement class]])
{
return (NSView *)[self nextResponder];
}
return [super hitTest:aPoint];
}
When run, it crashes on elementAtPoint with EXC_BAD_ACCESS code=2
Now, it gets weirder. If I breakpoint the app at that line, and do a po [self elementAtPoint:aPoint] in LLDB, LLDB just hangs until I do a ^C.
Weirder yet. If I comment out everything but the last return, break on the return statement, and run po [self elementAtPoint:aPoint] in LLDB—I get exactly what I expect, a nice dictionary telling me all about the DOM at that point.
What could be causing this behavior?
Note: This is on OS X, not iOS.
What could be causing this behavior?
Just look at [WebView _elementAtWindowPoint:] and [WebView _frameViewAtWindowPoint:] implementations in the WebKit source code. Unfortunately, they use hitTest: to determine elementAtPoint:.
In my case, this workaround seems to work:
- (NSView *)hitTest:(NSPoint)point
{
if (m_hitTestEnabled)
{
[NSTimer scheduledTimerWithTimeInterval:0.
target:self
selector:#selector(hitTestDelayed:)
userInfo:#[ #(point.x), #(point.y) ]
repeats:NO];
}
return [super hitTest:point];
}
- (void)hitTestDelayed:(NSTimer *)timer
{
NSPoint point = NSMakePoint([[timer userInfo][0] floatValue], [[timer userInfo][1] floatValue]);
m_hitTestEnabled = false;
NSDictionary *dict = [self elementAtPoint:point];
m_hitTestEnabled = true;
if ([[dict valueForKey:#"WebElementDOMNode"] isKindOfClass:[DOMHTMLDivElement class]])
{
NSLog(#"divAtPoint: %#", dict);
}
}
m_hitTestEnabled is set to YES in the initWith... method.
Why with a timer? Such operations on WebView are allowed only in main thread. So, we cannot launch another thread to get elementAtPoint: and wait for its completion in the "main" hitTest:. Maybe someone will come up with a better solution.

"Unknown Class <MyClass> in my Interface builder error" but I don't have a MyClass

Here is the error I am receiving
2013-07-30 22:20:53.227 Matchismo[562:c07] Unknown class PlayingCardCollection in Interface Builder file.
2013-07-30 22:20:53.229 Matchismo[562:c07] -[UIView setSuit:]: unrecognized selector sent to instance 0x71433f0
2013-07-30 22:20:53.230 Matchismo[562:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setSuit:]: unrecognized selector sent to instance 0x71433f0'
I don't have a class called "PlayingCardCollection" so I don't see how I could be receiving this error unless I named something wrong but I cannot find an error like that.
Here is some of my code
- (Deck *) createDeck
{
return [[PlayingCardDeck alloc] init];
}
- (NSUInteger) startingCardCount
{
return 20;
}
- (void)updateCell:(UICollectionViewCell *) cell usingCard:(Card *) card
{
if ([cell isKindOfClass:[PlayingCardCollectionViewCell class]]) {
PlayingCardView* playingCardView = ((PlayingCardCollectionViewCell *)cell).playingCardView;
if ([card isKindOfClass:[PlayingCard class]]) {
PlayingCard *playingCard = (PlayingCard *)card;
playingCardView.rank = playingCard.rank;
playingCardView.suit = playingCard.suit;
playingCardView.faceUp = playingCard.faceUp;
playingCardView.alpha = playingCard.isUnplayable ? 0.3 : 1.0;
}
}
}
And this is part of another file.
- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger) collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return self.startingCardCount;
}
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"PlayingCard" forIndexPath:indexPath];
Card* card = [self.game cardAtIndex:indexPath.item];
[self updateCell:cell usingCard:card];
return cell;
}
If anymore code is needed let me know. I have alot of files for this project but most weren't touched since my project had its last successful run. Thanks in advance!
Here's why your app is terminating:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setSuit:]: unrecognized selector sent to instance 0x71433f0'
Looking more carefully at the reason, notice that it says:
'-[UIView setSuit:]: unrecognized selector sent to instance 0x71433f0'
The message is telling you that your app tried to send a setSuit: message to an instance of UIView. The UIView class doesn't declare a setSuit: method or a suit property, so ordinarily this won't work.
The problem may or may not be related to the first issue, where it looks as though you set the identity of an object (possibly a view) in a nib file to a class that you later deleted or renamed. Look at the identities of the objects in the nib file (using the Identity Inspector tab), and see if you can find PlayingCardCollection.
If so change it to something more appropriate. Chances are, that's the indirect cause of the runtime exception.
The error says it all.The class name set to some view in interface builder as PlayingCardCollection and the class does not exist
To find out one best option is to select the nib and right click on it, open it as source code where it shows the xml structure representation of your nib
Then search for PlayingCardCollection and find it.Find the nib with that content and you can find the view from that nib ,More study on the nib itself can sort out the view easily

NSInternalInconsistencyException PDF Viewer

I copied some good pdf viewing code from Julius Oklamcak. https://github.com/vfr/Viewer
It works great in his app when I do not modify it, but it gets messed up when I put it in my own app.
I removed the print, bookmark, and tile view buttons fyi.
The DONE button is not working.
Here is the error I am receiving:
2012-12-18 10:01:45.857 TeacherTableView4[1147:907] *** Assertion failure in -[ReaderViewController tappedInToolbar:doneButton:], (...my path to)/TeacherTableView4/ReaderViewController.m:844
2012-12-18 10:01:45.859 TeacherTableView4[1147:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate must respond to -dismissReaderViewController:'
*** First throw call stack:
(0x371b52a3 0x3bd9497f 0x371b515d 0x3a2682af 0x40967 0x3c9f1 0x3676f0a5 0x3676f057 0x3676f035 0x3676e8eb 0x3676ede1 0x366975f1 0x36684801 0x3668411b 0x34a4f5a3 0x34a4f1d3 0x3718a173 0x3718a117 0x37188f99 0x370fbebd 0x370fbd49 0x34a4e2eb 0x366d82f9 0x414bd 0x36557b20)
libc++abi.dylib: terminate called throwing an exception
Here is the code:
- (void)tappedInToolbar:(ReaderMainToolbar *)toolbar doneButton:(UIButton *)button
{
#ifdef DEBUGX
NSLog(#"%s", __FUNCTION__);
#endif
#if (READER_STANDALONE == FALSE) // Option
[document saveReaderDocument]; // Save any ReaderDocument object changes
[[ReaderThumbQueue sharedInstance] cancelOperationsWithGUID:document.guid];
[[ReaderThumbCache sharedInstance] removeAllObjects]; // Empty the thumb cache
//COMMENTED OUT BY ME
//if (printInteraction != nil) [printInteraction dismissAnimated:NO]; // Dismiss
if ([delegate respondsToSelector:#selector(dismissReaderViewController:)] == YES)
{
[delegate dismissReaderViewController:self]; // Dismiss the ReaderViewController
}
else // We have a "Delegate must respond to -dismissReaderViewController: error"
{
NSAssert(NO, #"Delegate must respond to -dismissReaderViewController:");
}
#endif // end of READER_STANDALONE Option
}
I would really appreciate some help with this guys. Thanks!
I ran into the same problem using this PDF viewing code. I simply added this method
- (void)dismissReaderViewController:(ReaderViewController *) viewController
{
[self dismissModalViewControllerAnimated:YES];
}
to the .m file where I'm calling the - (IBAction)didClickOpen from.
This is mainly due to the fact that in ReaderViewController.m the delegate expects to see dismissReaderViewController declared in your implementation file. Otherwise, it will throw that error you're getting.
Note: Use [self dismissViewControllerAnimated:YES completion:nil]; for iOS6 or later since dismissModalViewControllerAnimated:YES was deprecated :-)

Problems passing data between different classes with a method

I have this in a class:
NSString *globalMidiData = #"30a0a00\n";
switch (IndicatorCheckNXT) {
case 1:
[testRobot checkTestRobot:globalMidiData];
break;
default:
break;
}
And in another class I have this:
-(void) checkTestRobot: (NSString *)midiDataGlobal{
bool pressed;
bool pressed2;
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
}
And I got this message:
-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0
2012-11-23 20:45:31.755 Exemple1[477:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate checkTestRobot:]: unrecognized selector sent to instance 0x18acb0'
What I am doing wrong?
Obviously you send checkTestRobot to the wrong object. testRobot seems to point to the AppDelegate and not to an instance of your class.
Also you should replace this:
NSString *miawmiaw =[NSString alloc];
miawmiaw=midiDataGlobal;
with:
NSString *miawmiaw = [midiDataGlobal copy];

IndexOutOfBounds looping though subviews?

I have a nethod to refresh the content of a UIScrollView. Within the ScrollView there are several UIImageViews and some UILabels.
I do clean the content of the scrollView with the following code:
for (int i = [publicationsScrollView.subviews count] -1; i>=0; i--) {
NSLog(#"Deleting SubView: %#", [[publicationsScrollView.subviews objectAtIndex:i] class]);
if ([[publicationsScrollView.subviews objectAtIndex:i] isKindOfClass:[UIButton class]] || [[publicationsScrollView.subviews objectAtIndex:i] isKindOfClass:[UIButtonLongTap class]] || [[publicationsScrollView.subviews objectAtIndex:i] isKindOfClass:[UILabel class]] || [[publicationsScrollView.subviews objectAtIndex:i] isKindOfClass:[UIImageView class]]) {
NSLog(#"Deleting SubView: %#", [[publicationsScrollView.subviews objectAtIndex:i] class]);
[[publicationsScrollView.subviews objectAtIndex:i] removeFromSuperview];
}
if ([[publicationsScrollView.subviews objectAtIndex:i] isKindOfClass:[iCarousel class]]) {
NSLog(#"carousel: View is in Scrollview");
}
}
This code ran fine for some days. Now i recieve an error during refresh in console:
refreshWorkSpace: deleting all subviews (11)
2011-11-25 14:04:52.826 CatalogService[45054:fb03] Deleting SubView: UILabel
2011-11-25 14:04:52.827 CatalogService[45054:fb03] Deleting SubView: UILabel
2011-11-25 14:04:52.839 CatalogService[45054:fb03] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 10 beyond bounds [0 .. 9]'
*** First throw call stack:
(0x1e8c052 0x231fd0a 0x1e78db8 0x6945 0x5826 0x1e8dec9 0xddc5c2 0xddc55a 0xe81b76 0xe8203f 0xe81bab 0xecfa99 0xed1407 0xe0193f 0xe01c56 0xde8384 0xddbaa9 0x28b6fa9 0x1e601c5 0x1dc5022 0x1dc390a 0x1dc2db4 0x1dc2ccb 0x28b5879 0x28b593e 0xdd9a9b 0x2e6d 0x2de5 0x1
I can not understand what's happening here. I loop through the subviews (count should give me the number of existing subviews !?). Why could the Index be out of Bounds !?
I would suspect the exception is being thrown on this line:
if ([[publicationsScrollView.subviews objectAtIndex:i] isKindOfClass:[iCarousel class]]) {
in the case where [[publicationsScrollView.subviews objectAtIndex:i] removeFromSuperview] has just executed there will no longer be an object at index 'i'. This would only happen if the last subview in the array was one of the types you delete - otherwise the access would be harmless.
To fix, you could just add a continue after the removeFromSuperview call.
Perhaps try replacing for loop with a fast enumeration, like:
for (UIView *aView in publicationsScrollview.subviews) {
.... rewrite code to reference aView instead of using objectAtIndex
}
and see if you get the same behavior.
In the first if, if it entered you remove the subview. So, you decreased the subviews count array.
After that you try again to take the subview, in the second if, and this subview was removed, that's why it's crashing.