How to implement add a index search view on top the tableView? - iphone

I want to add the index letter on top of the UITableView when touch the index, how to do it?

Can't find any third party implementation of this, which is surprising (I would be happy to be proven wrong). Looks like you'll have to code it from scratch by overlaying a thin UIView subclass on top of the table view (probably best to use core graphics here to draw the outline and the letters), intercept touches on it and determine which letter they are in contact with and then send appropriate scrolling instructions to the table view using
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

Well because you have already sections you can implement when willDisplayCell method is called to [self setTitle:[sectionsArray objectAtIndex:indexPath.section];
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath
*)indexPath

Related

Iphone: UITableView how to detect that row is selected

I have a UITableView, and I press the row, but do not release finger, so didSelectRowAtIndexPath is not called yet, right?
How to detect on which row i clicked? in which method?
How to detect that I clicked on table view? Is there any method like rowIsPressed? or onTableViewTouchDown?
There are two options at least:
1) You can subclass UITableViewCell and than use the touchhandling you know from a default uiview. (Like touchesBegan: etc.) / OR add a custom uiview as contentView of the tablecell.
2) Add a gesturerecognizer to each tablecell.
To find out in which row you are, you could give every row a tag (which than refers to the row) in cellForRow:atIndexPath:
try this
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
There is no such method to detect the selected state before lifting the finger... I guess you should override the UITableView class and add a UIGestureRecognizer to it.
And about your second question, I think you are talking about this table view delegate method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
But there is also another method that will give you the current selected row. This is it (directly from the table view class):
- (NSIndexPath *)indexPathForSelectedRow
Hope to have helped!

Indexed UITableView without section header

I'd like to implement a grouped and indexed UITableView without section headers.
I'm using sectionIndexTitlesForTableView:(UITableView *)tableView to return my titles.
I also implemented tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section and returned nil as well as tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section and returned 0.0f.
Both doesn't remove the section headers. There is still a space between the different sections.
I had the same problem and could not find a solution. In the end, I had to subclass UIViewController (not UITableViewController) and use a UITableView with transparent background and the style set to UITableViewStylePlain. Then, I created custom cells for the first and the last row (with rounded corners) and some transparent margin left and right. I can give you more details if you want, but as it does not answer your question straight, I'll just share this link for now.

Delete Button in UITableView

i want a Delete Button in my UITableView like in die AdressBook when editing a contact.
Is this a custom cell, or a UIButton?
To make such button you can do following:
Make your UITableView style Grouped.
Add +1 section to your table.
Say to your table that it is one cell for last section
Just return custom cell (with red background and appropriate label) for last section
If you implement the Delegate method's for edit the tableview
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
And than implement the DataSource method
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
For allowing to get that delete button when you swipe a cell use the
Cell Editing Style : UITableViewCellEditingStyleDelete
// Edit: Wrong answer.
Do you mean the Big one at the bottom or with the sign on the left?
use....
firstly use
[btn removeFromSuperview];
and
[tblobj reload];

Displaying a UITableView followed by an image, followed by more UITableViewCells

I've seen some applications on the iPhone have an image on top of the tableView, which is straight forward and can be set with something like tableViewHeader.. and a picture below set with tableViewFooter. I recently seen an application where there is an image in the header, a table view, then another image below the footer, and then subsequently a couple UITableViewCells...
Is there a straight forward way to accomplish this without using two UITableViews in the same controller?
Multiple sections will accomplish this, you can also use this method on your UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
in conjunction with a custom UITableView cell created in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This will allow you to specify a custom cell with the appropriate height that contains your image.
Use 2 sections.

[iPhone]How to customize header of Section in grouped TableView?

To customize cell, we implement class inherit UITableViewCell. Now, to customize header of Section in grouped UITableView (same to below picture), how to do? Please guide to me!
Implement tableView:viewForHeaderInSection: in your table view delegate.
Starting with iOS 5 you also need to implement
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
In addition to
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Otherwise it won't work.
From Apple's reference
The returned object can be a UILabel or UIImageView object, as well as a custom view. This method only works correctly when tableView:heightForHeaderInSection: is also implemented.