How can I create a custom scrollbar for a UITableView?
I want to remove the default one that pops up when tracking begins and that disappears when tracking ends. I want, instead, to have one similar to that in a computer program: (a) it's on the right side of the screen and permanently visible; (b) manually scrolling the bar will scroll the UITableView to the appropriate position; (c) scrolling the UITableView will scroll the scroll bar appropriately (without showing the default one that Apple provides).
The difficulty in (b) and (c) is that, as far as I know, Apple only provides methods to scroll to a particular row/section, but not to scroll to three-fourths of the way down a row. So, for example, if I want to scroll the scroll bar, the UITableView will subsequently only scroll to the top of a row/cell. The method I'm talking about is:
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Has anyone implemented a custom scroll bar in their UITableView before? Or can someone help me figure out a way to solve the following problems:
scrolling to any point in the UITableView instead of to the start of a cell
removing the default scroll bar and preventing it from appearing
changing the scroll bar image/animation/whatever as the UITableView is scrolled
Thanks!
UITableView inherits from UIScrollView, that means you can use any of the existing functions. In your case
– (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
should do the job. It moves the table to any position you want.
To disable the existing scroll indicator, use
table.showsVerticalScrollIndicator = NO;
And to add your own, just add your custom view!
Related
Currently, I'm displaying vertical section scrollbar in my table view:
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return [SectionModel getAllSectionNames];
}
I need to zoom-in the section name that is tapped on scrollbar, and zoom-in a little bit previous and next section names. The desired effect should be similar to DOCK behavior in MAC OS X. Any suggestions where to start?
UPDATE: Currently, I'm trying to find any scroll-to-section event but with no luck. UIScrollViewDelegate do not have such method.
Currently, I have realized that it's impossible to do that with native Apple methods. You need to implement that scrollbar from scratch.
Another option would be to use UIScrollViewDelegate method sectionForSectionIndexTitle:atIndex: that gets called when you tap on concrete section on scrollbar.Then you might create custom UIView with zoomed-in letter and present it on tableviews superview (for example at center). It's not the desired effect but some workaround.
I am looking for the most direct way to make it so that when the user taps a UITableViewCell, a keyboard appears. I want to use a custom keyboard (UIPickerView) and I preferably would like to make the cell style UITableViewCellStyleValue2. I can't seem to find a very direct way of doing this. I have a navigation bar on top, and hoping to make the buttons on that change as well...
Thanks!
First and foremost, to achieve this you're going to have to handle the custom animation of the UIPickerView sliding up and down. They keyboard is handled automatically by the controls that automatically need it (UITextField, UITextView, etc.).
So when your view loads you will want to create and configure your picker and then move its Y coordinate to CGRectGetMaxY([[UIScreen mainScreen] applicationFrame]);
Then in your - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath you will call a method that is responsible for animating your picker view into place. The only problem I foresee with this approach is allowing the user to dismiss this picker view in a way that makes sense as users are used to input views sliding only when they're needed (meaning that they appear when a view becomesFirstResponder and they disappear automatically when that view resignsFirstResponder status).
I think I understand what you're trying to achieve here and I would do it a bit differently. Instead of displaying a picker with options when you select a cell I would instead push a new tableViewController with your options laid out as cells. Then when the user makes a selection, you can set a checkmark and pop back to the original view.
Harrr pirates!
I'm trying to make a data entry screen using a UITableViewController. It contains a grouped table view with two sections, each with a few (2 and 4) rows with a UITextField inside them.
When any of the UITextFields become first responder they scroll into view automatically. Great, you would say, but I want to scroll the whole section into view, not just the row containing the UITextField that became first responder.
I don't allow the user to scroll the UITableView by hand and I know to what position it should scroll to display correctly. However, I can't get my UITableViewController to stop automatically scrolling the UITextField into view for me.
Searching StackOverflow I can find a lot of questions about how to resize the UITableView when the keyboard appears, but this doesn't stop the automatic scrolling.
Any suggestions? Your help would be much appreciated!
TableView is basically an extension of scrollView therefore if you want to do the scroll yourself you should use the scrollview API.
Set the contectSize property to the size of the screen without the keyboard and the contentOffset to the location on the table you want to scroll to
I have a table view inside a navigation controller, which is one view for a tab bar.
Everytime I launch the app, the horizontal scroll indicator flashes briefly when i select this tab.
Could this be related to the initial tab selected, which does contain a scrollview?
I was under the impression that table views couldn't scroll horizontally?
It doesnt seem to affect the app, just annoying thats all.
Do you do programmatic scrolling in your view?
We did this flashing on purpose in one of our apps, using some code to set a new scroll position (0) with animation enabled.
EDIT: There is also the method: flashScrollIndicators in UIScrollView (a UITableView also being a UIScrollView).
I want to display some kind of indication to guide user to scroll.
Usually when we touch the UITableView scrollbar appears if needed. But I want this scrollbar indication already displayed on my tableview.
How is it possible to do so?
If you have a table view that goes offscreen, you can call
[self.tableView flashScrollIndicators];
and they will flash to show the user that they are there. This is usually put in viewDidAppear.
(If you inherit from UITableViewController then you will have a self.tableView instance variable, if not then substitute another UITableView.)
If you a scroll view's entire contents fit within its view then no scroll bars are displayed; to test this display a table view with only one cell. If the content size is larger than the view's frame then scroll bars will be displayed; only then will [self.tableView flashScrollIndicators]; actually flash scroll indicators.
There's no way to force the scrollbar to appear, short of messing with the internals of UITableView(which you shouldn't do), or redesigning your own table view class.
Per the documentation of UIScrollView's showsVerticalScrollIndicator property: "The indicator is visible while tracking is underway and fades out after tracking."