- (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];
Related
//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
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];
}
I don't know why this doesn't work. indexOfIcon is correct, section is correct (checked with NSLog) If I select one everything is correct. But this line doesn't do a thing...why? If selected it should have a blue border. This works great while doing it "manually" but not with code..
- (void)viewWillAppear:(BOOL)animated
{
NSUInteger indexOfIcon;
if(self.mainCategory.icon){
indexOfIcon = [self.icons indexOfObject: self.mainCategory.icon];
} else {
indexOfIcon = 0;
}
[self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom];
}
add
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.selected = YES;
and the cell will be selected.
The command [self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom]; tells the collectionView, that the cell is in selected state, but don't set the state of the cell.
After years selection seems to work fine (even in viewDidLoad:)
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[_collection selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionLeft];
successfully triggers cell's -setSelected:
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];
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.