UITableViewCell- controlling movement - ios

When editing my UITableView, I give the option to move cells to reorder the data. However, The top two cells in the table are cells that give information about all of the cells in the table, and I dont want the user to be able to move information cells into that section. Here is a picture of the problem:
The user shouldn't be able to drag the cell titled 'This is bad!!!' into the section with the 'Total:' and 'New Group...' cells. Is there a way to control this functionality? I haven't seen a delegate method that does this, but I could have missed one.
Edit: oops! I just saw that someone else has asked the same question on SO, so I'm going to post the link and close this question. Thanks #fzwo for your help.
How to limit UITableView row reordering to a section

tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: from UITableViewDelegate is what you're looking for.
In your concrete case, you could also display the header information in the actual tableView.tableHeaderView. This scrolls like an ordinary cell, but isn't a cell. It would probably also make sense from a UI perspective, because it is something different than your ordinary cell content.

Related

How can I Create a Tableview Under Custom Tableview cell

I am just thinking. Suppose, i have a tableview which have custom cell. It's simple. But My idea is that, when i click a tableview cell then another tableview is appear under that tableview cell, and again i click that cell then that sub tableview disappear. Similarly when i click second cell than work same. Is it possible? Please Provide me any idea or reference.
This is entirely possible, you're talking about Expandable cells.
My example here
The general idea is that your custom cell has a tableview at the bottom of the cell, and what you do is just change the cell height to display said tableview, on tap.
It's not easy, I'm not gonna lie it took us a while to do it, but we managed, and I'm telling you, it's very possible.
You can find a lot of help using the Expandable Cell keywords.
Note that you're gonna find yourself handling a lot :
What to do when the expanding cells is shown off screen?
What to do when you're expanding the first/last cells ?
What to do when expanding another cell ?
What to do when scrolling inside that cell (a scrollview inside a scrollview !)
There are many cases where it'll work, but won't work fine, and there is gonna be a lot of fine tuning. Specially in our case where we have rounded corners, but only when the cell is expanded, and not in cases where it's the last or first cell (next to section header).
They look cool and make you feel proud, but don't say to your PM it'll be done in a week, because it's a pain to build.
If you want to show additional cell information, you can add more cells after the cell indexpath you have clicked.
Create a custom table view cell classCustomTableViewCell by subclassingUITableViewCell class. And system will generate CustomTableViewCell.h, CustomTableViewCell.m, CustomTableViewCell.xib files for you.
Add protocols UITableViewDataSource and UITableViewDelegate in your CustomTableViewCell.h and implement the required methods in CustomTableViewCell.m files
Add a method for setting datasource and use the datasource for updating the table.
NOTE:
Handle table-dequeue mechanism properly, otherwise you will end up
with weird issues that may take time to investigate and resolve.
If you use this custom cell for all the cells in your parent table then the gestures will only listened by the child table. So plan for that too.
Please visit my blog for the sample code. https://myioslearnings.blogspot.in/2017/03/nested-table-view-in-ios-objective-c.html

Table header view is swiped to the left when deleting a cell

First off, sorry if this is a duplicated question but after reading several posts with similar issue, I wasn’t able to find a clear solution.
The problem is what the title states: I have a pretty basic tableview, with only one section and a tableheader. When I delete one row, the table header also gets swiped to the left at the same time with the row being deleted.
I guess the solution is to return false in canEditRowAtIndexPath when I know it is the header calling, but I don’t know how to differentiate it from the rest of rows.
I tried tableView.cellForRowAtIndexPath but didn’t work, I guess it is because the header cell is not really part of the tableview as the normal cells are. In fact, I don’t know how to get the indexPath of my header cell. I also thought about tagging the header cell but, again, I don’t know how to get it back in canEditRowAtIndexPath.
Many thanks in advance!!
This may happen if you are using an UITableViewCell instead of an UIView in viewForHeaderInSection method. Please verify it.
If you have only one section and you don't really need a sticky header, you could also add the UIView to the tableView.tableViewHeader property. Please check https://stackoverflow.com/a/5442005/3211512 for an example.
I think, allo86 is right. Your header may be a UITableViewCell. However, I would suggest a little different approach. If you are having only one section then set an UIView on top of your Table view(outside of the table) but if you are going to have multiple sections, then set UIViews as headers accordingly for any section for which you want to have a header.

IOS table view inside of a table view

I have a table view with expanding cells for each of them. I want to make every expanding cell be a new table inside of the bigger one. Is that possible? I've done the research, someone said that duplicate UITableView cannot put in one file.
For example
dish order1
=================
dish order2
rice
coke
===============
dish order3
which every "dish order #" is a cell of a table, and when you expand one cell, there will be a smaller table appears. I've done all the expanding stuff. But don't know how to put a small table into a bigger one. Thanks
Well if i understand your question correctly, what you search is called nested tableView, here's some examples:
SDNestedTable
ExtensiveCell
CollapseClick
JKExpandTableView
Good luck.
It would likely be impossible to put one table view inside of another table view, and if you did manage to do it, it would be awful. Ask yourself, have you EVER seen this in a commercial app? If not, as a novice iOS developer, you are out of your depth trying to invent new UI paradigms.
Master the existing UI tools first. Don't try to use the UI elements in totally novel ways until you have a strong feel for the standard way to use them. Expect this to take 6 months or more.
Others have suggested a sectioned table view where initially only the first element of a section is visible, but when you tap on it, it expands to add other rows. This works quite well.
Another approach would be to use a master/detail UI, where tapping on one table view cell pushes a new view controller the uses a new table view to display detail information about the previously selected item. There are some use cases where you might have several levels of increasing detail.
I really do not think you want two instance of UITableView, instead what you want is a sectioned UITableView which expands when it's header is tapped. Apple has a good sample code for this here:
UITableView expand/collapse
i have demo for you , just got from github..
https://github.com/mitsBhadeshiya/ExpandingCell
i hope this is helpfull for you...
Have you considered using one UITableView with multiple sections? You can accomplish what you are depicting above with only one tableView.
Since this was a problem for many people in the past, iOS 9 has a thing called Stack View, it does exactly what you are saying.
Check out this article.

UITableViewCell resort without whole table reload

I now have some table with some custom cells in it. It' can be scrolled, cells provide some information and can interact with user with some buttons and so on.
Is where any way to resort the cells with some animation without whole table reload?
for example I have cells with tags 1, 2, 3, 4, 5 - placed as I wrote here. I want to resort it to become 2,5,1,3,4 for example - and user must see the cells moving to it's new place - but without table reload. Now I have to reload the table - so there is no any visual animation and to user it can be hard to understand what there is go on...
Maybe this question will help you:
UITableView animate row reordering upon sort
You probably cannot use the tag for each TableCell, but I cannot see how you get your data for your cells so can't help you much there. If you use a model, you could add a field to define the sorting order.
Hope this helps you in the right direction!
I complete with my own question, thanks to Laura for provide me help where I found the way to do what I want. The main point of it - to use
[_tableView moveRowAtIndexPath:indFrom toIndexPath:indTo];
for it. There is exist some not easy things here with indexPaths of items currently not visible on screen, but main thing - cell move - os ok.

Toggle showing/hiding child table cells iOS

I'm trying to create a UITableview that contains STATES and CITIES. To start with, I'd like the table to display only the STATES, with each value having a downward facing disclosure arrow on the right hand side of the cell which lets the user know it has values underneath it. If the user clicks the arrow, the table would expand to show the CITIES associated with the selected STATE. The user could then either select a CITY, or click on a upward facing disclosure arrow which would then "hide" the CITIES.
I've downloaded and reviewed Apples "Table View Animations and Gestures" example.
I was hoping someone might know a simpler way of accomplishing what I'm asking for.
http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
Good Job on explaining exactly what you want to do. This is how I would tackle this, I figure it would be easier to explain it without giving you meaningless code and answer any coding concerns you might have after.
I would set up the table view data source to be an array of arrays. The idea would be that every index in the array would represent a state and therefore contain a number of cities, hence ever index contains an array (array of cities). The parent array(of states) will be empty at the beginning, but the arrays(of cities) that will later fill it would be populated with the appropriate cities.
I would then set up the table view to contain sections (I a tempted to put code here, but read along). The sections would represent the cities. You can then fill out the table view with sections using (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section delegate. On the first run you can fill the actual table with one cell per section (maybe with the word "expand" or "more" and your down arrow). When the user touches that cell you can use the didselectrowatindexpath to know which section was touched (the indexpath object contains the section), now that you know which section it is, just modify the data source by adding the array of cities for that section of the array of arrays (parent array) and update the tableview.
This essentially gives your tableview an according style and feel. It is very easy to implement but requires a little bit of code. I have done this and am willing to provide the code you might need, the trickiest part would be to update the tableview in the correct way.
EDIT CODE:
I did a simple example following above explanation. The code is on Github , feel free to ask any questions about it.
I think a better way to represent this information would be to have a UITableView containing the states with each state showing a tiny arrow pointing to the right. Then, when a user clicks on the state, load the next UITableView that shows all of the cities in that particular state. Using a UIViewController for pushing the City list will allow users to easily return to the States list.
This approach will make much more sense to iOS Users, because this is how they expect Tables to work.
There are many tutorials explaining how to use UITableView. Here is a link to a site with many UITableView tutorials. The tutorial I linked to explains pushing a UIViewController on to the stack so that there is a simple back button back to the State list.
Normally such thing is done by seguing to another view and showing more details about cell.
What you want you could achieve by actually making custom UITableViewCell which would contain UIButton with arrow image and UITableView. In case button is clicked for the first time you could reload your cell and create inner UITableView which could show cities. Another click would simply reload cell again and not return inner UITableView at all. You also need to keep selected state somewhere because you may have to reload previous cell and hide inner table in case arrow in other cell is clicked.

Resources