How to draw a button over a last visible uitableview cell? - iphone

I need to display search button at the edge of last visible cell in uiTableView. Something like this:
I don't know how to get the right CGRect to draw this button (view) and how to redraw this, when the user scrolls the tableview.
Tnx.

The UITableView method
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath
should help you.
You may need to offset this by the tableview.frame.origin if you are drawing it in the parent view.
Hope this helps!

Another way would be to have the button attached to the View (rather than cell), On tapping the button you could find the NSIndexPath for last cell by iterating through visibleCells.

Related

Proper way to implement a footer in UITableView

So I read here that I can simply drag a UITableViewCell to the bottom of my UITableViewController in storyboard and have it act like a footer. This footer row has an activity indicator in it that's it. It's width is 320 and height 55 with the indicator centered in the row. Note that it's a UIView rather than a UITableViewCell because I can only get it to work with the former.
First, The UITableView doesn't stop at the footer. One can see the footer if he extends his scrolling beyond the bottom of the UITableView. As soon as the user releases his finger, the footer disappears from site as the UITableView returns its scrolling back to the last element. I am trying to do what Instagram is doing - if you scroll to the bottom you can see their custom activity indicator at the bottom and the UITable will remain its scrolling position at that indicator. How can I achieve this?
Second, I have some custom scrolling performed by certain user actions. Right now, I have the following code:
if (row + 1 < [self.tableView numberOfRowsInSection:0]) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:row+1 inSection:0]
atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
} else {
// TODO scroll a little down so the user can see the activityIndicator
}
How can I tell my tableView to scroll programmatically to the footer and have it stop there?
Third During the very beginning, my UITableView has to fetch things from my server before it can populate the tableView. Unfortunately i can't get the footer view to maximize the space of the UITableView so that the activityIndicator will appear in the center. Right now this is how it looks:
I think I have the structs set correctly:
I suspect that having a UIView within a UITableView might prevent the view from maximizing.
Summary
Any recommendations on the above issues? I apologize for the length of this question, but I feel that they are all related to the same problem mentioned above.
I finally figured it out.
With regards to #zing and #Lithu answers, that worked. However, returning a footerView from this method forces the footerView to "stick" to the bottom of the TableView. By this I mean that the footerview will always be shown (which is not something I want)
I finally used self.tableView.footerView = MyView. I disabled ALL the spring and struct settings on my UIView and it fits perfectly. (I've previously set it to maximize hoping to have it maximize when there is nothing in the table)
Regarding centering the activity indicator: I ended up setting the footer view to hidden if there's nothing in the UITableView (by checking in numberOfRows). I programmatically added the ActivityIndicator in the center if this occurs.
Thanks for all the answers!!
Did you try to do it in the proper delegate for UITableview Footer
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Use This code to add any view in the footer.
e.g.
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, self.tblView.frame.size.width, 49)];
return footerView;
}

How do I tell the difference between the user tapping my table view cell and the user tapping a subview contained within the cell?

One of my view controllers contains a UITableView with custom UITableViewCell's. My custom UITableView cell contains a UIImageView subview that represents a tappable icon. When the user taps anywhere on the custom cell, except the icon subview, I want my didSelectRowAtIndexPath method to be called like normal. But when my icon subview gets tapped, I want a different method to get called, but I can't figure out how to do this. Do I have capture the touch position in the touchesDidBegin method and manually check if the user tapped the icon? That just feels so hacky. Other, cleaner ideas?
Thanks so much for your wisdom!
Simply add a tapGestureRecognizer to the UIImageView in your cell

how to center uitableview selection with indexpath value

I am saving the indexPath selection from a subview and passing it to the parent view with delegates. When I got back to my subview from my main view I pass the indexPath back to it and show the user which cell they previously selected with a tick in the accessory view of the tableviewcell.
One problem being if the user has selected a cell out of a fairly big list its hard to find the cell they selected again incase they wanted to change it (being that they made a mistake)
I would like to know if their is a way to use indexPath or something similar to center the previously selected cell of the uitableview to the center of the screen?
UPDATE::
Here is a graphical view of what I am trying to achive to make it abit more understandable..
step one : select cell then go to subview and select the cell (value) you want to pass back to main view (save indexPath of selected cell)
step two: user either wants to change his selection or made a mistake and was ment to select the cell below the one they chose... repeat previous steps but display previously selected cell in the center of the view..
Have you tried the following function
[tableView scrollToRowAtIndexPath: atScrollPosition:UITableViewScrollPositionMiddle animated:YES]
a UITableView is a subclass of UIScrollView - try setting the Content Offset (figure out how much with the cell height and indexPath).
[tableView setContentOffset:CGPointMake(0, indexPath.row*cellHeight) animated:YES];
should work. You might want to do the math a little differently.

pop up detail view out of tableviewcell

I am working on a app where I want to expand a tableviewcell to cover almost all the screen with animation when it is selected by user. I am looking to create a uiview on the tableviewcell and expend it to cover major portion of the screen when user selects the row.
The main problem I am having is to get the frame from where my pop up view will start expending. How will I get the frame of the row which is touched?
Thanks
Pankaj
Is it crucial that the cell should not reposition?
If not ( i am guessing not, as you are anyway planning to cover whole screen):
When the cell is selected, scroll the cell to top (using scrollToRowAtIndexPath) and either insert your custom view to cell's contentView or modify its parameters if its already there with different opacity/size etc
Use UITableView function to get the rect for the row by passing the its NSIndexPath.
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath

How to interact with a UITableView displayed overlapping another UITableView

I have one UITableView displaying some data, and when the user begins typing in a UITextField above the UITableView, another UITableView is displayed below the UITextField to show suggestions. This "suggestions" UITableView overlaps the UITableView below the UITextField. Tapping on one of the suggestions will populate the text box with the item tapped.
The suggestions UITableView displays in front of the other UITableView, but problem is that none of the taps to the suggestions UITableView register if they're outside the bounds of the view that contains it.
This is probably a really simple problem dealing more with UIViews in general, but I'm having trouble. Thanks for the help!
You have to adjust your second tableview which is giving you suggestions below testfield which will solve most of your issues
hope it helps you
you can show the second UITableView within another view that is displayed above the current view, like a popover, using
[self.view addSubview:secondView].
Once a selection is made, you can remove this view using
[secondView removeFromSuperview];