UITableView inside custom UICollectionView - ios

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.

Related

Unable to dequeue a cell with identifier while using a custom UITableIView

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

Move CollectionViewCell to another section

I have a UIViewController with a collectionView inside it. The layout may seem confusing but I am making use of horizontal scrolling UICollectionViewCells, presented in 3 sections.
The main collection view is made up of 3 sections. I access 3 different UICollectionViewCell classes for each section becuase it is fetching different data for each one. Once the data is fetched, it dequeues another Cell class, which is the same one accessed for all the sections.
There are 2 buttons in each cell. When I press the button, a value changes within the database. When I re-run the program, the cell in which the button was pressed has moved to its corresponding section that it should be in as per the change. However, I want to achieve this as soon as I press the button. How can I move the cell from one section to another, baring in mind that they the cells presented are inside a collectionview cell making up the sections, which is then inside a greater UICollectionView.?
I've tried researching how to do this but no luck, and everyone seems to be using a drag and drop method which seems too complicated for what I am trying to achieve. Would appreciate any help.
Thanks
The approach I followed to achieve the above situation is using a custom Delegation when cell is removing from collectionviews. A container CollectionView has two sections with 2 different cells containing two different Horizontal UICollectionViews. These two collectionview's cells have UIButtons. When tap on one collectionView's button, that particular cell is removed, custom Delegate method calls and another CollectionView's cell is populated. This is the link of the project I have created for this particular scenario. For better understanding, here is a GIF for demonstration.

How to add a subview to a TableViewCell?

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];

UICollectionView: Get indexPath of Cell that is not visible

I have a UICollectionView with several cells – there are always some of them outside the viewport, so there are cells being reused.
When an event occurs I want to take a specific cell and move it to the front of the UICollectionView. In order to make moveItemAtIndexPath() work I need to know the current indexPath of the Cell that I want to move.
When I initialize the Cells in the CollectionViewDelegate with the cellForItemAtIndexPath method I save its indexPath into a variable of the Object that is the model of the Cell (not it’s actual Object, just the model). Then I look at this variable when I want to move the cell.
This is working fine as long as the cell was visible once – it seems like it only initiated then, even though it is part of the CollectionViewData all the time.
How can I make sure my CollectionViewCell has an indexPath, even when it is not visible or has not been visible yet?
If you know what data (cell) you want to present at the front (I assume top) of your UICollectionView, why don't you just update your dataSource and reload your UICollectionView?

How to make two tableview cell in one controller class in iphone

I am making two tableview cell in one controller class on vertical style. I have different value both the cell. Left cell have some name value for eg(name :pradeep),and right side cell have some price value so if select on left cell on 3row and right side cell on 2 row so this two cell value I have to pass for open url.
Please help on this how to know which cell index are selected from both the tableview cell and what the value on that selected cell.
If I understand your requirements correctly then you should probably be using a UIPickerView:
http://www.youtube.com/watch?v=wnxS35JDqok
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html
You can add multiple tableview cell. You need to separate or identify them using Identifier. After creating custom cell, you can add tableview cell into Cellforrowatindex path method.Make sure don't forgot to import "custom cell.h" in your implementation file. Thanks.

Resources