Displaying an arrow for indicating user to scroll up or down in a UITableView in objective c - objective-c

I want to display an arrow which indicates the user to scroll up or down in a table depending on the data in the table.
i.e Down arrow indicating user to scroll down or Up arrow indicating scroll up.
How can i gt the current status of the table to display arrows?
Many Thanks,
Avi.

Since UITableView is the subclass of UIScrollView. Implement the followin UIScrollView delegate in you view controller:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (tableView.contentOffset.y <
tableView.contentSize.height - tableView.frame.size.height)
downArrow.hidden = NO;
else
downArrow.hidden = YES;
if (tableView.contentOffset.y > 0)
upArrow.hidden = NO;
else
upArrow.hidden = YES;
}
DownArrow and uparrow shoulf be your images placed at the appropriate positions on your view.

Related

VoiceOver only speaks two cell and skips remainder cells

My app has a banner that is made with horizontal UICollectionView.
And the data of banner get from server.
The banner has two or more count (test count was 4.).
But the VoiceOver only speaks two cell and skips remainder cells.
View Hierarchy is
ViewController > TableView > CollectionView
CollectionView in TableViewCell
- (void)setVoiceOver
{
self.isAccessibilityElement = NO;
self.collectionView.isAccessibilityElement = NO;
}
CollectionViewCell
-(void)setArr:(NSDictionary *)arr
{
_arr = arr;
[self setVoiceOver];
}
-(void)setVoiceOver
{
self.isAccessibilityElement = YES;
self.contentView.accessibilityElementsHidden = NO;
self.accessibilityLabel = [NSString stringWithFormat: "ad%d", _arr["bannerId"]];
}
I want to make VoiceOver reads all banner cells.
I guess the VoiceOver can access the collectionViewCell which is appeared in the screen.
I tested several apps, the cells that I can access with the voiceover swipe gesuture are over the screen a little bit.
like this.
enter image description here
So the voiceover have to adjust to collectionview, not the collectionviewcell.
And we can access each cell by scrolling gesture (three finger swipe)

How to get currently activated view?

Hi in my project i have 3 views in a single .XIB file. I am using a scrollview to show one view at a time.(When we swipe only one view shown in the screen). Is there any way to identify which view is currently showing on the screen?
You can try this
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate {
// tag is 0 , 1 , 2
NSInteger tag = scrollView.contentOffset.y / singleViewHeight;
}
Dont't for get to set the delegate
self.scrollView.delegate = self

Intercepting UIScrollView Scrolls

I have a UIScrollView and a UITableView inside the UIScrollView.
I would like to intercept scrolling of the UITableView and only allow scrolling if the super view (UIScrollView) have reached a specific contentOffset.
I have created subclass of both UIScrollView and UITableView, how do i catch scrolling event and intercepting the scrolling while the user is still scrolling?
Example of what i'm trying to accomplish:
The UITableView is going to have a header, if i scroll down the header will collapse to 30% of original size and and stay visible at the top. After i have scrolled back to the top of the UITableView i want the header to expand. In other word i want to extend the scrolling of a UITableView with a header that can collapse/expand.
There might be better way to accomplish this, i'm open for suggestions.
There may be a better way, but this solution is working for me.
UITableView (let's call it innerScrollView) inside of UIScrollView (let's call it scrollView) inside whatever the main view is (let's call it view).
Set an outlet in your view controller for the innerScrollView (self.innerScrollView).
Set bounce in XIB or code to: scrollView.bounces = YES and innerScrollView.bounces = NO.
Set scrolling to disabled initially for the innerScrollView.
In code (viewDidLoad:) set scrollView.contentSize.height to view.frame.size.height + the 70% of the header you want to disappear. Resize innerScrollView to fill the resized contentView to the bottom.
Set your view controller as the delegate for scrollView and implement scrollViewDidScroll: as follows:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat maxYOffset = self.scrollView.contentSize.height - self.scrollView.frame.size.height;
CGFloat minInnerYOffset = self.innerScrollView.contentInset.top;
CGFloat currentYOffset = scrollView.contentOffset.y;
CGFloat newYOffsetDelta = currentYOffset - maxYOffset;
CGFloat currentInnerYOffset = self.innerScrollView.contentOffset.y;
if (scrollView.contentOffset.y >= maxYOffset) {
self.innerScrollView.scrollEnabled = YES;
self.scrollView.contentOffset = CGPointMake(0, maxYOffset);
if (currentYOffset != maxYOffset) {
self.innerScrollView.contentOffset = CGPointMake(0, currentInnerYOffset + newYOffsetDelta);
}
}
else if (currentInnerYOffset > minInnerYOffset) {
self.scrollView.contentOffset = CGPointMake(0, maxYOffset);
self.innerScrollView.contentOffset = CGPointMake(0, currentInnerYOffset + newYOffsetDelta);
}
else if (currentYOffset < scrollView.contentInset.top) {
scrollView.contentOffset = CGPointMake(0, scrollView.contentInset.top);
}
else {
self.lowerScrollView.scrollEnabled = NO;
}
}
I just whipped this up and quickly tested it. It all seems to work, but there may be some improvements and tweaks needed. Regardless, this should get you started at least.
Well, you should use the following UIScrollViewDelegate method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
// here perform the action you need
}

How to add AutoScroll to Scrollview in iOS?

I am having Scollview in iOS. In that scrollview I have two Table Views.
If the contents of Table view get increased dynamically (by row), then I want to add the AutoScroll to the Scrollview.
Anybody has any idea about this?
Thanks in advance.
you this following line to make one time autoscroll.
set x if you want to scroll horizontally, otherwise set y to scroll vertical.
[scrollView setContentOffset:CGPointMake(x, y) animated:YES];
i code like this in the text field....
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == expenseAmount)
{
[self.expenseScrollview setContentOffset:CGPointMake(0.0,50) animated:YES];
// [self registerForKeyboardNotifications];
}
if(textField == exchangeRate){
[self.expenseScrollview setContentOffset:CGPointMake(0.0,120) animated:YES];
}
return YES;
}
by following this idea you implement that in table view increment [at the point u need to set ]
and the thing u need to increase the scroll size means u need to use this....
scrollView.contentSize = CGSizeMake(yourWidth,yourHeight);

Objective-C : Endless UIScrollView without pagingEnabled

In my iPhone app there is a scrollview pagingEnabled=NO which can contain up to 200 subviews (150 x 150) and the challenge is to do lazy loading and simulate endless scrolling (without bouncing) in horizontal directions.
Is there a solution or an alternative for this request?
Lazy loading of a scroll view is demonstrated in one of Apple's sample code projects: PageControl.
To fake endless scrolling what I'd suggest is to make your scroll view very wide to begin with, wider than an average person would scroll in one set of scrolling behaviors. Then in your delegate methods -scrollViewDidEndScrollingAnimation:, -scrollViewDidEndDragging:willDecelerate: and -scrollViewDidEndDecelerating:, one or more of which will be called after the user is done scrolling, reposition your content to exist in the center of the scroll view and update your contentOffset point without animating.
For that to work visually you would need to also disable the horizontal scroller. You'll also need to consider how to determine what view to draw at a particular contentOffset with this method since you won't be able to just divide the contentOffset.x by the scroll view's bounds anymore to find out where you are.
Hello I found the way to do it.
I have a master array with all the subviews (in my case they are images, so I store the names).
The scrollview only has 3 subviews: left, current, right.
Paging is enabled, so the user cant really spin more that one view left/right at any time.
What I do is:
1) track his current position on the master array. If he moves left, subtract one; right add one. Like this:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[some code to determine current page, based on contentOffset]
if (page == 0){
NSLog(#"Going left");
if (currentPage > 0){
currentPage--;
} else {
//cycle to last
currentPage = [images count] -1;
}
} else if (page == 2){
NSLog(#"Going right");
if (currentPage < ([images count] -1)){
currentPage++;
} else {
//cycle to first
currentPage = 0;
}
} else{
NSLog(#"Not moving");
}
2) after the user moves, I reload 3 new images, like this:
//updates the 3 views of the scrollview with a new center page.
-(void) updateScrollViewForIndex:(NSInteger)newCenterPage{
//fist clean scroll view
for (UIView *sView in [scroll subviews]){
[sView removeFromSuperview];
}
NSInteger imgCount = [images count];
//set center view
[self loadImageIndex:newCenterPage atPosition:1];
//set left view
if (newCenterPage > 0){
[self loadImageIndex:newCenterPage-1 atPosition:0];
} else {
//its the first image, so the left one is the last one
[self loadImageIndex:imgCount-1 atPosition:0];
}
//set right view
if (newCenterPage < imgCount-1){
[self loadImageIndex:newCenterPage+1 atPosition:2];
} else {
//its the last image, so ther right one is the first one
[self loadImageIndex:0 atPosition:2];
}
}
3) Finally re-center the scroll view to the center view again:
[scroll setContentOffset:CGPointMake(1 * viewWidth, 0)];
Hope this helps, although "the man with the plan" is Mr. Clark, who pointed the way.
Gonso
Matt Gallagher has a blog post which describes a solution to this exact problem. I've used it and it works great.
The UIScrollView and UIPageControl in Cocoa Touch allow for user interfaces with multiple panning pages. The sample project that Apple provides (PageControl) keeps all child views for every page in a lazily loaded array. I'll show you how you can implement this using just two child views, no matter how many virtual pages you wish to represent.
It works by shuffling around the child views and reseting their content when necessary. I used this for displaying flash cards, where there could be anywhere from 3 to 3,000 items. Although it's set up right now for paging, I'm sure you could get it to work with regular scrolling.