In my setup, I have 3 tableViews (nested) - tableView inside a tableView cell inside a tableVIew cell.
My goal is to find out touch events on the “mid-level” tableView. When a mid-level tableView is touched, I would like to extend its and its parent tableView height to predetermined values.
I created a custom UITableView with a second tag property (“secondTag”) and inside the tableView methods, I cast tableView to CustomTableView. So, inside tableView didSelectRowAt I'll had two indexes - IndexPath and secondTag. The first one was theIndexPath of the mid-level tableView and the second one was the custom UITableView tag that used for the indexing of the “parent” tableView.
But despite setting the cell identifier properly (inside the storyboard) I got the following error: "unable to dequeue a cell with identifier middleCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard".
One more note: inside tableView didSelectRowAt I used reloadData() on both the mid-level tableView cell and its parent tableView cell, since I needed both of them (sub/parent tableView cells) to change their height after a touch has occurred.
I think the double reloading may be the cause of my problems but I must reload both the parent and its nested “mid-level” tableView since I need both their heights to change after a touch was made.
*This question comes in to continue the following one: Need help adding new stored property to UITableView
Related
I have a uitableview with 2 custom cells (messages, and notifications). I want to apply a segue to another viewcontroller when user press the message cell, but do nothing when he press the notification cell. how to do this with didselectrowatindexpath method? some answers here suggested using indexpath.row for checking which cell is clicked but I get these dynamic cells from json so I don't know where their position is in the tableview or how many are they.
using swift and xcode 7.3
If the cells are different types, you can just determine the class type in didselectrowatindexpath
Or you can add a different tag to the cells. You can do this in the storyboard or programatically when you create the cell.
Then in didselectrowatindexpath check what the tag is for the selected row and you will know what type of cell it is.
I have tried to create a custom cell that would display a list of items. To achieve this I tried to create a custom cell with UITableView inside it with scroll disabled.
The problem I have with this is when i try to apply changes to the cells in the inner UITableView data just does not get updated and the cell stays as it was. I have tried calling [tableView reloadData], [cell setNeedsDispaly], [cell setNeedsLayout] to no avail.
It seems like the data that has been applied when the cell was initialised persists through any attempts to change it. Though, when I create a breakpoint in cellForRowAtIndexPath: the data does get updated but is not rendered.(e.g. text property of UILabel has new value, but text is old on the screen.)
You need to nil the cell and then reload the table view. For some reason iOS caches table view data and stuff doesn't get updated correctly.
You could try overriding UITableViewCell's prepareForReuse(): in that method you can set all the cell's outlets/properties to nil. You would do this for the cells in the main cell's table view. I am assuming those are custom cells as well and that you have a custom UITableViewCell subclass for them.
Refer [I have two views on one cell, when I click on a cell it will be hidden and one edit form will be expanded on that. How to resolve that? ..check in accepted answer methods ...
[tableView reloadRowsAtIndexPaths:ll withRowAnimation:UITableViewRowAnimationAutomatic] in didSelectRowAtIndexPath
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.
As the title says, i'm trying to put one UITableView inside a custom UICollectionViewCell, i made it so it's perfectly displayed, but now i need the touches inside the Cell that contains the Table to call the didSelectRowForIndexPath method.
I have a .xib for this custom UICollectionViewCell, inside it i have the UITableView, and i have it's delegate and datasource correctly set.
Now, if i run this, the CollectionView cells are loaded with their proper data (this is, each cell with a table containing the proper rows), but if i try to select one row from one table, the CollectionViewCell is selected instead of the TableViewCell (this is expected, but not what i need).
I'd like to know if is there a way for the TableView row to get selected, even if it's inside a CollectionView cell.
Thank you and sorry for my english.
I have a UITableView, to which I add cells via UIButton. On creation the cell gets its textLabel & detailTextLabel from 2 arrays. However, if an item with the same Title already exists in the table, I want to change the detailTextLabel.text of the existing cell without adding a new cell.
So is there a way to update the detailText of a certain UITableViewCell when it was already created with some value?
Maybe I should just remove the old one and add new?
Creating of a UITableView cell should be just that, creation and not population of data, since we re use cells we should always assume the cell data is stale and needs a refresh, therefore you should always have a way to reset the values of the cells, if you have a custom cell you should expose the controls you are using and set their values accordingly in cellForRowAtIndexPath, if you require to change a cell you should either change the data source values and reload the cell via - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation , or grab a hold of the cell with cellForRowAtIndexPath and change the values accordigly... my point is no need to recreate the cell..