The navigation bar is not displayed at the end of the tableview. What am I doing wrong?
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if([indexPath row] == [tableView numberOfRowsInSection: 0] - 1){
[self.navigationController setNavigationBarHidden:NO
animated:YES];
DDLogVerbose(#"Reached end of tableview");
}
}
The "Reached end of tableview" is outputted to Xcode, but the navigation bar (previously hidden), does not re-appear.
I have also tried using willDisplayCell but that shows the navigation bar too early, just before the last cell is on screen, this is not ideal.
Why does the navigation bar not re-appear at the end of the tableview, even though the if statement is entered? What should I do to make it re-appear?
Update: Great answers everyone, although I'd also appreciate if someone could possibly explain to me, why the above code does not work. Thanks!
UITableView is a UIScrollView, so you can use its scrollViewDidScroll: delegate method to decide, based on its contentOffset vs. contentSize, to show or hide just about anything.
Well it's not the best solution, but you could try adding another row (dummy row at the end), then when willDisplayCell for that row gets called, you should the navigation bar, hiding the dummy row.
In view didLoad set navigation bar hidden
[self.navigationController setNavigationBarHidden:YES animated:NO];
And then check this method works or not
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
float offs = (scrollView.contentOffset.y+scrollView.bounds.size.height);
float val = (scrollView.contentSize.height);
if (offs==val)
{
// Code
}
}
May this help you .
Related
I am currently writing an app that downloads the RSS feed of a wordpress website and displays it in a table view. When you tap on an item in the list, it goes to the details view and displays the content. However, I have a strange issue with the segue to get from the Table View to the Detail View whereby the segue is not performed immediately after tapping on a row, but only when another row is tapped afterwards. The content displayed is that of the first selection.
For example, if i click row 1, it is highlighted but there is no transition. Nothing happens until I click another row, at which point the segue is performed to the detail view which shows the information for row 1. I have the following methods to perform the segue:
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedFeedItem = _feedItems[indexPath.row];
[self performSegueWithIdentifier:#"detailSegue" sender:self];
}
and
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DetailViewController *detailVC = segue.destinationViewController;
detailVC.selectedFeedItem = _selectedFeedItem;
}
I am very new to objective-C and iPhone app development so apologies if this is an obvious issue. Any help appreciated. Thanks.
You have...
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
(deselect)
You need...
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
(select)
I have a tableView. My tableView cells do have a detail accessory.
My question: How can I push another view controller when the detail button is presses.
When I normally press the cell, my ViewController1 opens. But when I tap on the little i on the right of the cell, I want to push a different view controller.
How can I do this?
it is just like DidSelectRow u need to modify DidSelectRow to accessoryButtonTappedForRowWithIndexPath
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// if u using .Xib
yourviewcontrollerName *vie=[[yourviewcontrollerName alloc]init];
[self.navigationController pushViewController: vie animated:YES];
//// if u using storyboard
[self performSegueWithIdentifier:#"yoursequeName"
sender:self];
}
you need more information use this link Pushing to a Detail View from a Table View Cell using Xcode Storyboard
Use this code it works
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// Push new View controller here
UIViewController *objVc=[[UIViewController alloc]init];
[self.navigationController pushViewController:objVc animated:YES]
}
I have two view controllers, the main linked to a navigation controller. I created a segue by linking the main controller to the second on the storybaord. I've called the Identifier "Associate" and made it a push segue.
I create table view cells with a button attached to the accessory view programatically (this is deliberate). The button calls performSegueWithIdentifier, but it doesn't show the second view controller. Aside my iffy technical language (only been IOS for a week, sorry) any idea what I'm doing wrong?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyIdentifier"];
//...
[myButton addTarget:self action:#selector(buttonizeButtonTap:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = myButton;
return cell;
}
-(void)buttonizeButtonTap:(id)sender{
[self performSegueWithIdentifier:#"Associate" sender:sender];
}
OK, realised what I did wrong. I had put an empty performSegueWithIdentifier method override. The danger of running before I can walk. Thanks for all your help.
I have a UITabBarController template based app where the first tab is a UITableViewController with custom buttons in the cells. I need one button in one cell to call a specific tab in the parent UITabBarController. Im using this code in the didSelectRowAtIndexPath:
case 5:
NSLog(#"Search");
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Get UITabBar instance and send it message
UITabBarController *tabBar = (UITabBarController*)[self parentViewController];
[tabBar setSelectedIndex:1];
break;
When I tap on this row the app crashes without any log in the console. Im calling this in that UITableViewController which is the first tab in the UITabBarController.
PS I also want to avoid the blue selection on this cell that occurs when the user taps. So I added this code:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 1:
return nil;
break;
}
}
But it still selects blue when I tap on it. Could they be related issues?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
UITabBarController *tabController = (UITabBarController *) UIApplication.sharedApplication.keyWindow.rootViewController;
[tabController setSelectedIndex:1];
}
the first message will deselect the row, avoiding the blue selection.
As your app is tab-based, the root controller of the key window is always an instance of UITabBarController.
I have a UITableView embedded in a UIPopoverController, as shown below.
When I select a cell, the textField in the cell becomes firstResponder. But instead of keeping the tableview scrolled to the top, all content goes away (even though there are no more than 4 cells). It is impossible to scroll to the top will this happens. After dismissing the keyboard everything is normal again.
The following code does not resolve the problem:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
CRShoppingListItemCell *cell = (CRShoppingListItemCell *) [tableView cellForRowAtIndexPath:indexPath];
cell.itemTextField.enabled = YES;
cell.itemTextField.delegate = self;
[cell.itemTextField becomeFirstResponder];
[tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionNone animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
My guess is you aren't using the UITableViewController. Inside that controller's viewWillAppear it checks for isInViewControllerThatHandlesKeyboardAvoidance (private) and one of those controllers is the popover controller. So if it is that then the keyboard avoiding behaviour you would usually want when the table is full screen is turned off.