collectionview scrollToItemAtIndexPath is not working with pagination - ios

//Scroll to top
NSIndexPath *index=[NSIndexPath indexPathForRow:0 inSection:0];
[self.collectionview scrollToItemAtIndexPath:index atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
I tried this code but it is not working
[self.collectionview setContentOffset:CGPointMake(0,250) animated:YES];
with this code also the same result only

Related

Collection View is skipping one row When using scrolltoindexpath

I am using the collection view and i am trying to make infinite scrolling in collection view using the following method:
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
if (infoArray.count-1 == self.indexPathForVisibleCells.row) {
[self.collection_View scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO]; // [self.collection_View scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
}
}
When i am using this method, when it comes at last cell and then it moves to the cell with index 1 not to the cell with index 0. Can someone explain this behaviour and give a possible solution to this ?
you must try this-
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]
atScrollPosition:UICollectionViewScrollPositionTop
animated:YES];
for more please refer following link-
http://www.tuicode.com/question/58707ef3c116a36d35c56c21

How to select a uitableview cell programmatically?

I have a UISearchController and i want to select the first row of the searchResultsController tableview on click of search button in the keyboard.
For that I tried implementing
-(void)searchButtonClicked:(UISerachBar*)searchBar {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.searchResultsController.tableView selectRowAtIndexPath: indexPath animated:false scrollPostion:UITableViewScrollPositionNone];
[self.searchResultsController tableview:self.searchResultsController.tableView didSelectRowAtIndexPath: indexPath];
}
but it didn't work for me!!
Then I tried to make a separate method:
-(void) plotPinOnMapWithIndexPath:(NSIndexPath*)indexpath;
and called it in didSelectRowAtIndexPath and in searchButtonClicked method by passing the indexPaths.But the problem is that the cell doesn't get highlighted the way it gets highlighted when user clicks on it.
This works for me, and is correct:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
optionally try this:
[self.tableView:self.tableView didSelectRowAtIndexPath:indexPath];
or you can use Segue to continue with result:
[self performSegueWithIdentifier:"showDetailView" sender:self];
In prepareForSegue method you pass parameters....
It worked!!
-(void)searchButtonClicked:(UISerachBar*)searchBar {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self tableview:self.searchResultsController.tableView didSelectRowAtIndexPath: indexPath];
}

TableView cell not scrolled on top after 3rd section in iOS7

I want scroll table view cell on top after clicked on cell, It is working up to 1 and 2 section but after that cell hidden behind "Keyboard".
- (void)scrollCellOnTop:(NSIndexPath *)indexPath
{
if(IS_IOS7)
{
self.supplierDetailTable .contentInset = UIEdgeInsetsMake(SCREEN_X,SCREEN_Y, self.supplierDetailTable.bounds.size.height-50, 0);
}
else
{
self.supplierDetailTable .contentInset = UIEdgeInsetsMake(SCREEN_X, SCREEN_Y, self.supplierDetailTable.bounds.size.height*tableInsetFraction, 0);
}
[ self.supplierDetailTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
Please give me a solution if you have.
In order to scroll to a row in table view, you should do like below instead:
NSIndexPath *showOnTop = [NSIndexPath indexPathForRow:row_index inSection:section_index];
[table scrollToRowAtIndexPath:showOnTop atScrollPosition:UITableViewScrollPositionTop animated:YES];
Try replace line:
[ self.supplierDetailTable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
with:
NSIndexPath *iP = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
[self.supplierDetailTable scrollToRowAtIndexPath:iP atScrollPosition:UITableViewScrollPositionTop animated:YES];

Highlight first table Cell, issues

- (void) SelectFirstCell
{
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionBottom];
}
Hello, i have this very simple method that is supposed to highlight the first Table Cell, but it is not working, the method does get called, and the values do match, Row 0 inSection 0 does exist.
But it does not get highlighted ?
If it makes any difference it is a table created by the Tapku Calendar View
Its worth mentioning that i am very new to Obj C
Try this:
[self.yourTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
Try this:
- (void) SelectFirstCell
{
NSIndexPath * firstElement = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:firstElement];
[self.tableView selectRowAtIndexPath:firstElement animated:NO scrollPosition:UITableViewScrollPositionTop];
}
Hope it help!
you can use this
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView selectRowAtIndexPath:indexPath animated:TRUE scrollPosition:UITableViewScrollPositionNone];
[[tableView delegate] tableView:tableView didSelectRowAtIndexPath:indexPath];

how to access tableview cell

i have a menu that contain 6 cells 1st one contain UIViewController the second contain UITableView
when i click the first cell a new page appear,and it contain a button
when i click this button i want access to the second cell from the Menu, that contain a tableView
// use this code for to Refresh or delete or insert TableviewCell
// reloading cell
NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil] withRowAnimation:UITableViewRowAnimationTop];
// inserting cell
NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil] withRowAnimation:UITableViewRowAnimationTop];
// deleting cell
NSIndexPath *tmpIndexpath=[NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:tmpIndexpath, nil] withRowAnimation:UITableViewRowAnimationBottom];
As much i understand your question you want to move from a tableview to other view on click..So,you have to use code similar to this..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Detail *img1=[[Detail alloc]initWithNibName:#"Detail" bundle:Nil];
img1.labelString = [titleArray objectAtIndex:indexPath.row];
[self presentViewController:img1 animated:YES completion:nil];
}
Write following coed in your UIButton Tapped Method.
-(void) ButtonTapped:(UIButton *) sender
{
NSIndexPath *indexpathNew = [self.tblView indexPathForCell:(UITableViewCell *)[sender superview]];
NSLog(#"%#",indexpathNew.row);
}
indexpathNew is return indextPath of selected button of cell.
Try my code i might be helpful to you.

Resources