iOS7 Strange behavior of UIPickerView with an UIImage as custom view, any official info? - ios7

I was following a tutorial on how to build a custom picker with an UIPickerView in Sams Teach Yourself IOS6 Application Development in 24 hours and I've noticed that simply returning an UIImage in (UIView*)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view method of the UIPickerViewDelegate does not work properly: the images do not appear correctly (they rotate on the spinning wheel but for example they disappear when they should move over the current selection's row). I've found a solution at this link on Stack Overflow and it effectively works, but I'd like to know if this strange behavior appeared in IOS 7 is due to a new way of using UIPickerView or if it is more a sort of bug.. I did not find anything useful in the official API Reference docs. Is there any official doc that is talking about the change in how we must return an UIImageView to be used in a UIPickerView

It looks like the answer is 'No'. I also looked through the Release Notes for 7.0 & 7.1 and looked at the differences in the references for UIPickerView, UIPickerViewDelegate, and UIView (among others) and couldn't find anything do explain why it behaves this way now and I couldn't find any changes to UIPickerView or anything it inherits from or conforms to that would explain it. (If there is something there that explains it then it was not immediately obvious to me.)
As far as I know, those are the only places that would have any official information on this.
I think the only way to know for sure whether this is deliberate or a bug is to report it.

Related

MKPinAnnotationView no longer using images in ios9

Since the iOS9 upgrade, the custom images on my MKPinAnnotationView are no longer showing up. Is there a documented change somewhere?
Per someone from Apple on the developer forums:
MKPinAnnotationView manages its own pin image. If you'd like to set a
custom image, it's best to use MKAnnotationView directly.
From: https://forums.developer.apple.com/thread/3920
I was doing this as well, and a simple switch to use MKAnnotationView worked for me. My guess is this was never supposed to work. I couldn't find any documentation on an image property for MKPinAnnotationView

Ongoing NSTableView problems

I am writing my first Cocoa/OSX app. I have been having problems with an NSTableView derived class. The problems is that there is no table in the containing NSView - the table is not visible.
I previously pasted my code at NSTableView is not being displayed
If you know NSTableView well and it could assist, it would greatly help. I have spent a couple of days on this, with no luck.
Additional details:
NSLog shows that NSTableView subclass init() is called once. This is probably good. The method numberOfRowsInTableView() is called multiple times. I don't know whether this good or bad. The method tableView:objectValueForTableColumn:row: is never invoked. The method drawRect() of NSView is called after initialization of TableView. Yet, commenting out [super drawRect:dirtyRect]; line changes nothing.
Please note that I use the same NSTableView subclass as [also] a NSTableViewDataSource. I understand that this is not the common "pattern," yet I don't see why this cannot work. If there is a logical explanation, please advise my approach is not workable.
I do not use and do not want to use InterfaceBuilder.
Thank you for taking time to read my question.
I managed to come up with the solution. See the referred page for more information, if interested. Thanks.
BTW, the best NSTableView tutorial which I have seen - one that allowed me do what I needed is at: http://www.knowstack.com/nstableview_fromcode/

Is Apple deprecating UIPopover?

Since iOS 5.1 was released, the default for showing the Master view controller in split views is a slide in type of thing. In order to present a popover it seems like you have to enable it using a UIPopover controller instead. Does this mean that the popover is going to going out of style?
When it comes to Apple's API's, deprecated means that Apple has specifically stated that something is in the process of going away. It's usually accompanied by advice regarding a new way to accomplish the same thing. So, if Apple ever deprecates UIPopoverController, you'll know it just from reading the documentation.
That said, it's also a good idea to read the release notes for each new version of iOS that comes along. In the iOS 5.1 release notes you'll find a note that explains what you're seeing:
In 5.1 the UISplitViewController class adopts the sliding presentation
style when presenting the left view (previously only seen in Mail).
This style is used when presentation is initiated either by the
existing bar button item provided by the delegate methods or by a
swipe gesture within the right view. No additional API adoption is
required to obtain this behavior, and all existing API, including that
of the UIPopoverController instance provided by the delegate, will
continue to work as before.

Using -presentModalViewController:animated: with UITabBarController NOT animated

So the rootViewController for this application is a UITabBarController subclass. And we're having a bizarre issue where we cannot get a UITabBarController to -presentModalViewController:animated: if we're passing NO to animated. We've tried a variety of methods: -viewDidLoad, -viewWillAppear, -viewDidAppear and can only get it to work if we do it after a delay, which is hacky.
I decided to break this out into a test and found that if I have a UIViewController that calls -presentModalViewController:animated: in the -viewDidAppear method it works as expected with both YES and NO for the animated parameter. However if this VC is instead a UITabBarController, it works if animated is YES but not if it is NO.
Any ideas? Is this a bug? I've searched online and through documentation and can't find a reason that UITabBarController shouldn't be able to present a view this way.
This definitely sounds like a bug. I'd suggest you file a bugreport with Apple. If it's blocking your project, you could submit it through one of your support incidents with Apple, and if they find it really is a bug they'll refund that support incident (so you don't loose anything). If it isn't a bug, they'll be able to give you a solution.

Best way to capture key events in NSTextView?

I'm slowly learning Objective-C and Cocoa, and the only way I see so far to capture key events in Text Views is to use delegation, but I'm having trouble finding useful documentation and examples on how to implement such a solution. Can anyone point me in the right direction or supply some first-hand help?
Generally, the way you implement it is simply to add the required function to your view's controller, and set its delegate. For example, if you want code to run when the view loads, you just delegate your view to the controller, and implement the awakeFromNib function.
So, to detect a key press in a text view, make sure your controller is the text view's delegate, and then implement this:
- (void)keyUp:(NSEvent *)theEvent
Note that this is an inherited NSResponder method, not a NSTextView method.
Just a tip for syntax highlighting:
Don't highlight the whole text view at once - it's very slow. Also don't highlight the last edited text using -editedRange - it's very slow too if the user pastes a large body of text into the text view.
Instead you need to highlight the visible text which is done like this:
NSRect visibleRect = [[[textView enclosingScrollView] contentView] documentVisibleRect];
NSRange visibleRange = [[textView layoutManager] glyphRangeForBoundingRect:visibleRect inTextContainer:[textView textContainer]];
Then you feed visibleRange to your highlighting code.
It's important to tell us what you're really trying to accomplish — the higher-level goal that you think capturing key events in an NSTextView will address.
For example, when someone asks me how to capture key events in an NSTextField what they really want to know is how to validate input in the field. That's done by setting the field's formatter to an instance of NSFormatter (whether one of the formatters included in Cocoa or a custom one), not by processing keystrokes directly.
So given that example, what are you really trying to accomplish?
I've done some hard digging, and I did find an answer to my own question. I'll get at it below, but thanks to the two fellas who replied. I think that Stack Overflow is a fantastic site already--I hope more Mac developers find their way in once the beta is over--this could be a great resource for other developers looking to transition to the platform.
So, I did, as suggested by Danny, find my answer in delegation. What I didn't understand from Danny's post was that there are a set of delegate-enabled methods in the delegating object, and that the delegate must implement said events. And so for a TextView, I was able to find the method textDidChange, which accomplished what I wanted in an even better way than simply capturing key presses would have done. So if I implement this in my controller:
- (void)textDidChange:(NSNotification *)aNotification;
I can respond to the text being edited. There are, of course, other methods available, and I'm excited to play with them, because I know I'll learn a whole lot as I do. Thanks again, guys.