Stop UIPickerViewAnimation - xcode

Is there a way to instantly stop the animation of rolling UIPIckerView or UIDatePicker on button click.

Look into - (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component
Since Picker can only show limited number of results at a time. You can implement an algorithm to determine what is in the middle of the result when this method is called. It gets called every time a new option appears (just like tableView viewForIndexPath). So scrolling up or down will call this method.
Beware, you would need to add padding options to first few choices and last few choices just so that it works correctly. This will get you the effect you want. Be warned, Apple might not agree with this method as it doesnt act like what Apple intended picker to do.
Let me know if it works.

If you look at the UIPickerView class reference, you'll see:
selectRow:inComponent:animated:
Selects a row in a specified component
of the picker view.
- (void)selectRow:(NSInteger)row
inComponent:(NSInteger)component
animated:(BOOL)animated
You could call this method when your button is pushed, sending NO for the animated parameter, to instantly select a particular row.

Related

NSWindow display and setViewsNeedDisplay

In NSWindow class I found, among others, two methods: display and setViewsNeedDisplay:. But I don't know the difference between these two methods. Although documentation says: "You rarely need to invoke this method", I need to call one of these to update window's contentView. The problem that the I don't know which method to call. Maybe somebody can tell me difference between those 2 methods?
Thanks.
P.S.contentView of window is my custom view.
For both windows and views, display method redraws the object immediately, and setViewsNeedDisplay:/setNeedsDisplay: set a flag that redraw is needed while the actual redraw will happen later. Repeatedly displaying a view is expensive, repeatedly marking it for display is very cheap.
Most of the time you need to call setNeedsDisplay: on the view you want to be redrawn. Or even setNeedsDisplayInRect: to mark only a part of it, not the whole view. So if all you need is contentView to be redrawn, call [[window contentView] setNeedsDisplay:YES] and that will be it.
In rare cases, for example, before invoking a blocking API call or displaying a modal alert, you will have to call display on the view instead, otherwise the call will block for a long time before redraw happens.
In even more rare cases, you will have to call display on the window, for example, if you tinkered with areas outside content view, like title and borders.
And you almost never need -[NSWindow setViewsNeedDisplay:]. I don't know an example when one needs it.

UIPicker and Text and URL

I'm trying to build an app that will display stats for a certain game (I'd rather not say which one). I have most of the app completed, but I have run into a problem with my "Players" page, which is the primary view that loads after viewDidLoad. I've attached a screenshot of how it looks.
(DARN IT. I'm too new to post a pic. Available on request.)
It took some work, but I finally got my UIPickerView into place, and customized the initial options for it. You can't tell from the screenshot, but the picker loads with my player name, and one other. This will change before release.
My problem is that I want users to be able to enter their gamer name(s) in a text field, and have them always selectable from the picker after that. When they select a name in the picker, I need that action to send a string, a URL, with the player name appended to it, to every other view so that all navigation subsequent to choosing a player will show that player's data. This will allow me to load the rest of my server side graphics with ease.
Also, player names must be removable from the picker.
I'm not so lazy as to simply ask for the code, but I can't seem to figure out what components to use, or even find a tutorial that speaks to what I'm doing precisely.
OK what i understand is you want to do two operations on the picker value select.
send the url with the player name.
delete the player name..(if user wants).
Now for this you can add two buttons and as you know the value that are shown in the picker is basically you can store them in am array and load it again on picker.
so now you added two buttons one is for sending data and other is for delete.
on sendData button you can do like this to select the value from picker
NSInteger row;
NSArray *repeatPickerData;
UIPickerView *repeatPickerView; //this your picker, if you defined it already dont do it.
row = [repeatPickerView selectedRowInComponent:0];
self.strPrintRepeat = [repeatPickerData objectAtIndex:row];
now in the "strPrintRepeat" you have the selected value. you can do what ever you want with it.
and on deleting the player name..you can do something like this.
NSInteger row;
NSMutableArray *repeatPickerData; //this should be mutable
UIPickerView *repeatPickerView; //this your picker, if you defined it already dont do it.
row = [repeatPickerView selectedRowInComponent:0];
[repeatePickerData removeObjectAtIndex:row];
now at this point you have the player name removed.
Then you can use your UiPicker delegates to reload the picker with the updated data..
Hope that works..:) enjoy

How to "stick" a UIScrollView subview to top/bottom when scrolling?

You see this in iPhone apps like Gilt. The user scrolls a view, and a subview apparently "sticks" to one edges as the rest of the scrollView slides underneath. That is, there is a text box (or whatever) in the scrollView, that as the scrollView hits the top of the view, then "sticks" there as the rest of the view continues to slide.
So, there are several issues. First, one can determine via "scrollViewDidScroll:" (during normal scrolling) when the view of interest is passing (or re-appearing). There is a fair amount of granularity here - the differences between delegate calls can be a hundred of points or more. That said, when you see the view approach the top of the scrollView, you turn on a second copy of the view statically displayed under the scrollView top. I have not coded this, but it seems like it will lack a real "stick" look - the view will first disappear then reappear.
Second, if one does a setContentOffset:animated, one does not get the delegate messages (Gilt does not do this). So, how do you get the callbacks in this case? Do you use KVO on "scroll.layer.presentationLayer.bounds" ?
Well, I found one way to do this. When the user scrolls by flicking and dragging, the UIScrollView gives its delegate a "scrollViewDidScroll:" message. You can look then to see if the scroller has moved the content to where you need to take some action.
When "sticking" the view, remove it from the scrollView, and then add it to the scrollView's superview (with an origin of 0,0). When unsticking, do the converse.
If you use the UIScrollView setContentOffset:animated:, it gets trickier. What I did was to subclass UIScrollView, use a flag to specify it was setContentOffset moving the offset, then start a fast running timer to monitor contentOffset.
I put the method that handles the math and sticking/unsticking the child view into this subclass. It looks pretty good.
Gilt uses a table view to accomplish this. Specifically, in the table view's delegate, these two methods:
– tableView:viewForHeaderInSection:
and – tableView:heightForHeaderInSection:

Changing tooltips in a custom view

I've got a sample project at:
http://ericgorr.net/cocoadev/tooltip.zip
What I would like to do is define a single tooltip rect for an entire view but be able to change the tooltip as the cursor moves inside of the view.
Is there a way to do that? Is there a way to force it to hide the current tooltip and display a new one while calling view:stringForToolTip:point:userData:?
I could create my own window that simulates a real tooltip, but wanted to make sure there was nothing built-in that would support this.
Check the MAAttachedWindow sample project:
http://mattgemmell.com/source/
Great start for creating custom tooltips.
NSView has specific handlers for mouse events.
Simply change the NSView (tooltip) based on these events.
I added some snippets to get you started.
- (void)mouseMove:(NSEvent *)theEvent {
NSPoint mousePositionInWindow = [theEvent locationInWindow];
}
- (void)mouseDown:(NSEvent *)theEvent {
}
- (void)mouseDragged:(NSEvent *)theEvent {
}
- (void)mouseUp:(NSEvent *)theEvent {
}
Response to comment:
Once I struggled with exactly the same problem: One view with continuous tooltip updates showing the cursor position and some additional information. I got it never working with the native tooltips. Finally i came up with the solution above, which is easy to implement and made it even look better.
Instead of using the separate window, you can also draw the custom tooltip inside the NSView itself, in relation to the cursor position. You can also put an extra NSView on top of the existing NSView to show the custom tooltips.
I don't like the native tooltip behavior. Apparently they have build-in time-delays which cannot be changed, for example: The cursor has to be on one position for some time to show the tooltip for the first time. Once the first tooltip showed up, the next will show with much less delay, but it's still quite annoying.
Of cours, you can always show the info in a label located near the view, which is really easy to implement. But that is no real answer to your question :)

Prevent selection change in NSOutlineView when NSActionCell clicked

I have a custom NSActionCell used to render some parts of some of the rows in my NSOutlineView. I can receive and respond to clicks on the NSActionCell, but the selection also changes when that cell is clicked. I'd like to prevent the selection from changing if one of my custom NSActionCells are clicked.
Is there an easy way to do this?
To answer my own question:
If the cell you want to be able to click (and subsequently not select a row) is in it's own column, then the following Apple example is very useful:
DragNDropOutlineView
That example relies on implementing the following NSOutlineViewDelegate method (implemented in AppController.m at line 304):
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
If you have a cell within another cell, you can still use that approach, but you'll need to do a bit more work to determine whether the mouse was clicked within your sub-cell. A good example demonstrating that logic is the following Apple example:
PhotoSearch

Resources