I like to implement UI like this screen.
as you see, when I touch a specific cell, pickerview appears at the bottom of that cell.
and it sits between two cell. and pickerview doesn't seem to be a subview of cell.
How do I implement this? I don't know where to start...
You can insert a new cell which contains a UIPickerView when user tap on a cell by using this method -
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Also for this you need to handle your data structure carefully by which you are populating your UITableView.
You can checkout this repo, it might help you -
https://github.com/saadnib/InsertPickerInTableView
Related
I need to add a subview to TableViewCell when the button in TableViewCell is clicked it should show another tableview as a subview and height of the tableview should be dynamic according to number of cell.
How can I do this?
Above screenshot is taken from a very popular shopping app and I need to do the same in my project.
You can easily achieve this using simple UITableView. For that you need to set all your main categories as your UITableview section and respected sub-categories can be added to respective rowOfSection.
You can use just one table view with UITableViewStyleGrouped style, and set "Men","Women","Kids & Baby" as TableView sections header, keep an boolean value to determine the result of "numberOfRowsInSection:" of each section and reload tableview.
See the below link at github:
https://github.com/OliverLetterer/SLExpandableTableView
This contains the Expandable TableView, which you required. You have to implement SLExpandableTableViewDelegate and SLExpandableTableViewDatasource which contains different method, in which you have to provide inner tableview as well.
Hope this helps you.
You need to do some work on your own I can give the directions that'll give you a way from my point of view :-
Make a Custom cell which you want to expand.
While designing the cell make its height in storyboard like 200 or so according to your need and add all the elements those you want to see when the cell is expanded.
You'll need two delegate methods first -didSelectItemAtIndexPath and second HeightForRowAtIndexPath at index path.
First You need to make sure the user taps on the button or cell that you want to expand , and to achieve that you need to call didSelectItemAtIndexPath.
Once you get your cell Position, in HeightForRowAtIndexPath check the indexpath is equal to your cell's indexpath,if yes then return the exact height(ie:200) of your cell otherwise return the default(ie:70) height of you cell.
Note : In didSelectItemAtIndexPath you need to call to method to update the current cell
[self.tableView beginUpdates];
[self.tableView endUpdates];
I'm subclassing UITableViewCell so I can design my own cells with gestures, etc.
One of the things I'm trying is to delete the cell/row after swiping.
My gesture recognizers are all setup and working nicely, however I'm unsure on how to tell the UITableView to delete this object. How can I reference the parent tableView, tell it which row to delete from within the UITableViewCell subclass?
Thanks
You could define a delegate protocol in your UITableViewCell subclass, add a method like cell:didSwipeRightToLeftGesture, and have your cell call its delegate when that happens. Then when your controller receives that delegate message, delete the row from the data source and update the table view.
You could also use UITableView's built-in swipe-to-delete as well.
I need to create a UITableView with multiple columns. In that, there will be a constant block on the top row of the table. When the user scrolls through the table, the row which is there in that block, will be picked. Basically it is a table view with UIPickerView.
I wish I was able to upload an image to explain this.
I'm not sure how to go about this. This is a hybrid of UITableView and picker view. Can I implement this is as a picker view of course with multi column (the block acting as a custom picker)?
Please help.
Thanks,
~Vishal
YOu can get an index to the data represented in your top row using the UITableView method:
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
where point would be (CGPoint){0,0} (or some point which intersects with your block/row 1)
or
- (NSIndexPath *)indexPathForRowsInRect:(CGRect)rect
where rect would relate to you "block".
you will want to manage the scrolling so that the table comes to rest with the top of a row aligned with the block or top of the table. This UITableView method may prove helpful, you should trigger it when your tableview comes to rest after a scroll:
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
atScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated
with UITableViewScrollPositionTop as the scroll position
I expect you want each column to scroll independently. In that case you would need one tableView per column. Then you just need to make sure you know which tableView is doing the message sending in your respective delegate and datasource methods (easy to manage as a pointer to the tableView is the first parameter sent in those methods).
The purpose of this question is not to know when a UITableView is done loading its data (which has been answered in this post) but to know when a UITableView has done drawing all its cells.
Using the visibleCells property inside the
- (UITableViewCell *)tableView:(UITableView *)iTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method doesn't work because when the tableview is loaded for the first time, no cells are visible yet.
The idea is to animate the cell appearance when the tableview is refreshed.
This seems like a complex task to perform but I'm surprised Apple didn't provide any delegate method to use when a tableview is done loading.
Better try this method, pass NSArray of indexPaths that you want to reload with given set of animation
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Hope it works
I don't believe there is a method that indicates when a table has loaded it's cells. However, you can achieve your goal of animating in the table cell whenever it is drawn.
Logic:
UITableView displays UITableViewCells as needed.
Each UITableViewCell is a subclass of UIView.
UIView has drawRect, which is called every time the view is drawn.
So, put your animation in UITableViewCell's drawRect method & it'll animated whenever it's drawn.
Implementation:
Create a subclass of UITableViewCell,
Apply this subclass to your table cells,
Add the drawRect method, and
Implement your animation in the drawRect method.
I have done this in one of my projects and it worked great. It draws the animation when the table is loaded or scrolled and when the display is rotated. With this approach you don't need to know when the table is done loading – each cell is simply animated whenever it is drawn.
One final note – if you put another view controller on top of your table view and then dismiss it, you may need to reload the table and set each UITableViewCell to setNeedsDisplay. This will force drawRect to be called again for each UITableViewCell.
I have a UI table view loading data from network. If the user move the finger on one cell, one button will be displayed, just like iPhone style delete button. If the user click this button, the value of one label in the cell will be changed accordingly. However, I didn't find any way to make table view to re-draw this cell, except for reload the whole table. I don't want to use reload data method, because I just need change the value in one cell instead of the whole table. Any suggestion on this?
Take a look at the method
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Calling this method will result in your table view's data source asking its delegate for information about that cell.
For future reference, I found this very easily by checking the documentation on UITableView. I suggest you do that in the future before posting here.