Is there a way to add rows to a UITableView by tapping a row, then the table animating to display some 'hidden' rows of data? Much in the same way you can tap the nearest day in the iOS 5 weather app and show an hourly view of the weather?
How about the:
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
method of the UITableView class?
Basically, on a row press:
provide a different height for your row
tableView.beginUpdates
tableView.endUpdates
You'll need to implement a custom cell. The hidden display elements should be already drawn in the custom cell. When beginUpdates triggers tableView: heightForRowAtIndexPath: you should provide your updated height. After endUpdates is called, this will cause the tableView to slide down your existing cell.
Related
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
In my application, I am using tableview with some rows. In each row I am displaying some part
of text.In that row below text there is a Expandbtn. If we click that we will display the whole
text.
For that I want to use reloadRowsAtIndexPaths: WithAnimation: method . I want to apply this
method when I click Expandbtn in each cell.
I am using that above method for expanding text in cell. My Problem If I expand text in first
and go to 2nd cell it appears to be expanding and it is overlaping with first cell.
If I scroll the table to the top, then first cell appears to be NOT Expanding.
Can Anyone Help me in this.
Thanks in Advance.
Relating to "If I scroll the table to the top, then first cell appears to be NOT Expanding." It sounds like you are not dynamically determining the height of the rows.
Are you implementing the delegate method - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath in your NSTableViewController? If so, make sure you are returning a different value before and after you expand the row.
I would like to have a custom UITableViewCell that displays limited data while unselected, but then expand to show more details when selected.
The issue I have is how do I adjust the size of the cell during a select/deselect event?
Make a sub-class of UITableViewCell, and override the drawRect() method.
In your view controller's didSelectRowAtIndexPath, you can switch between the contracted and expanded states. You can change frame sizes, add or remove sub-views, add more data, whatever you need to do.
I was doing it not so long ago. To adjust the size you need to make UITableView call heightForRowAtIndexPath again. It will cause redrawing of cell. Use
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
in order to do that. If you set animation to YES it will nicely animate expanding of your cell. Also to adjust cell, setSelected: in your UITableViewCell subclass may be helpfull.
I have a UITableView with some rows in it. Is it possible to show a UIPickerView when tapping on a row in the table?
I want the UIPickerView to change its data depending on which row it the UITableView that is selected.
If you set a delegate set for UITableView then that view will send you the appropriate delegate methods. From there you can reload your picker view. Click here to find out more.
edited: corrected link.
This is driving me nuts.
I have a TableView with custom cells. My cell contains a editble textview. Is it possible to change rowheight on cell and textview dynamicly (when I editing the textView) ?
best regards
You can't change the height of a tableview cell without reloading the table. This means that every time a new line is needed in the textview, the tableview needs to reload.
While this can be done (with much manual tweaking,) I don't think the results will make for a good interface. Instead, you should have the cell open a detail view and let the user type there. This is how all the Apple apps handle the same problem and it is the solution most users will expect.
It will also save you a heck of a lot time and frustration.
The row height is calculated from either the delegate or the table view's property. I think the height is determined when the cell comes into view.
One possible avenue is to use - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation.
Is the cell with with the text view unique in the table? You may run into problems if the user is in the middle of editing and the cell needs to be re-layed out and the text view is not unique.
yup!
try resizing your cell and calling
[tableView beginUpdates];
[tableView endUpdates];
every time you need to resize your cell.
that will call heightForRowAtIndexPath: and resize all your cells accordingly
so you want to return the proper height there..
hope that helps:)