I want a table view with only cels, and when you click on a cell it should expand and show more info of the clicked cell.
I've seen quite some topics on this, but the most of them are linking to Table View Animations and Gestures on the apple developer page. Which does it in a different way. They use header sections, but I want to use the cell which is expandable for layout reasons.
I already tried several things mainly with
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isSearching && indexPath.row == selectedIndex) {
return 110;
}
else {
return rowHeight;
}
When I Click on the cell, the cell is expanded but the info in that cell stays the same. Also the heigth of the cell when expanded should be related to the amount of text in the details.
Thnx!
You can achieve this through the use of custom cells. Create two custom cells, one for the normal row and other for the expanded row. When the user touches a particular cell, you can record it's indexPath and reload the tableView. While reloading you can change the height of this selected row using the code that you've just posted(increasing the height of only the selected cell). This would give an effect of expanding cell.
Related
To establish some context :
I have a UITableView with n cells.
When the user selects a cell they the cell expands and the user experience then continues within that cell.
There are some animations that take place within the cell.
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
//expand cell/increase cell height animated
//add a button to bottom of cell with target(didpressbutton:)
}
- (void)didpressbutton:(id)sender
{
//perform complex animating rearranging UI elements
}
At the end of the flow the user needs to comeback to the original tableview.
But the cell with the misaligned UI elements are still showing as it is dequeuing the old cells.
Is there any way for me to clear the cached cell or reinitialise them?
But the cell with the misaligned UI elements are still showing as it is dequeuing the old cells.
Is there any way for me to clear the cached cell or reinitialise them?
You are obviously misusing -prepareForReuse:. Implement this method to reset any state the cells have.
I am currently using the following tableView delegate method to adjust the height of individual cells when they are selected:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat height = 44.0f;
if (self.selectedIndexPath && indexPath.row == self.selectedIndexPath.row){
return height + 20;
}
return height;
}
This function works fine when the cell adjusted is not the last cell to be shown. However, if its the last cell, the function adversely affects the height of all the trailing empty cells as well, as shown in the illustration:
Not last cell (user "bansvsiena" selected)
Last cell ("newregistant" selected - notice all the trailing cells also have the same height)
Is there a way to fix this issue? Thanks!
There are two possible solutions for you:
Why don't you remove separator from all your empty cells? You can set yout UITableView's separator style to single line etched. Doing this will not show separators for your empty cells.
After setting self.selectedIndexPath value (I suppose you did it in tableView:didSelectRowAtIndexPath:) you are reloading your table. You can void doing this and just do following
[_tblCredits reloadRowsAtIndexPaths:#[indexPath, self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
As your all the cells will be created with 44px height at first and you won't be reloading the table so height will change only for those rows which you pass in array. This approach is much better to reload only those rows which need to reload instead of whole table.
Hope this helps :)
I have a UICollectionView inside of a normal UIViewController.
Inside the collectionview I have designed the reusable UI for the collectionviewcells in storyboard.
Inside of the collectionviewcell there is a label that displays the cells indexpath.row and 5 UIButtons which if selected, change color and stay selected.
I have set up the collectionview so that if more that 30 cells are requested the collectionview will page horizontally, the collectionview layout is also horizontal.
The application runs nicely, scrolls properly and lays out cells correctly.
The problem I am having is when you select for example button A in cell 1 in the collectionviewcell (which is suppose to layout 100 cells) and page over two pages (60+ Cells) to page 3, button A in cell number 75 is selected. And further more if you scroll to the end (100 cells) and scroll back to page 3, button A in cell number 75 is on longer selected, but button A in cell number 64 is selected.
Here is some snippets of code:
cell.m - controls the action from the user.
- (IBAction)bubbleButtons:(id)sender {
for(UIButton *bubbleCell in self.bubbleButtons) {
if (bubbleCell.touchInside && !bubbleCell.selected) {
bubbleCell.selected = YES;
} else if (bubbleCell.touchInside && bubbleCell.selected) {
bubbleCell.selected = NO;
}
}
}
MainViewContoller.m - sets up cell from UICollectionViewCell made in storyboard
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Cell *cell1;
cell1 =[collectionView dequeueReusableCellWithReuseIdentifier:zCellID
forIndexPath:indexPath];
cell1.numMainLabel.text = [NSString stringWithFormat:#"%d |",indexPath.row+1];
return cell1;
I do not really understand what is wrong or what is causing this bug, I am assuming it has todo with the view being reloaded when a new part of the view becomes visible but that is just a guess. Help would be greatly appreciated.
Zach
It's probably because the reusable view is reused.
The proper way to do this is to create custom reusable view subclass.
And save the selection of those 5 button.
cell1 =[collectionView dequeueReusableCellWithReuseIdentifier:zCellID
This line here might or might not give you a new cell, it might give you a cell that is used before. So, you need to update the selection in there. Or it stay the same as the cell it's reusing.
The Uicollection only generate the cells that are been displayed at that moment, so when a cell disapier from the visible view, its been replace with the new one.
So when you seleted the cell 75 and you scroll down, until the cell 75 is no visible, and then you scroll back to cell 75, you are generating a new cell, with a new button that is not seleted because is new.
So what yo could do, is save which buttons had been selet, and in
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
ask if the button thats is been displayed at that moment need to be selected..
Hope its helps
I have a situation where I need to display more than one sections in a grouped table. Each section has three content rows and I need a "View More" row. The content row will open a detail view, where as "view more" will open a tableview with status messages. Need some help with
The prototype cell is set to have the image and the labels. So I am not sure how to add the "View More" Row in the end.
Am I right in using dynamic prototypes ( I have it working pretty much) or is static cells the right choice?
The prototype cell is set to have the image and the labels. So I am not sure how to add the "View More" Row in the end.
You are not limited to a single prototype cell per table. Add a custom cell for the "View More" cell, then add some code to your tableView:cellForRowAtIndexPath: method to pick the "main" prototype for the top cells, and the "view more" prototype for the last cell.
-(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
UITableViewCell *cell;
if (indexPath.row != [self numberOfRowsInSection:indexPath.section]-1) {
cell = [tableView dequeueReusableCellWithIdentifier:#"mainPrototype"];
...
} else {
cell = [tableView dequeueReusableCellWithIdentifier:#"viewMorePrototype"];
...
}
return cell;
}
Am I right in using dynamic prototypes ( I have it working pretty much) or is static cells the right choice?
Yes, this is the right choice.
Create an array to contain all the status messages. Group them according to the section when you initialise the screen. You could give the same index to the groups as the section as well. In the didSelectRowAtIndexPath method, when a particular section is clicked, pass the particular section of the status messages to the next view controller.
Hope you get my idea and this helps you..
Adding the custom cell to the end of each section can be done as #dasklinkenlight said...
It's My first time to post a question, thank you for you all in advanced.
Now, i want to implement a default style grouped UITableView contains multiple group of data. for each row, there will be a detail Disclosure button as accessoryType icon. when people click on the disclosure button, i want the Cell expand with detail info for the selected row.
i was trying to fulfill this task by add a customized cell to selected row, however, it was very complex. So currently, i am trying to finish this task by reload a specific row with Customized cell xib. i knew there is a delegate method for reloadRowsAtIndexPaths. but can i use this to reload a specific cell? Thanks
please suggest!
Great Thanks
Have you tried something like this:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == mySpecialSelectedCell)
{
//Load all your custom stuff here
}
else
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
}
if (cell == nil)
{
}
return cell;
}
You would have to get the cell's indexPath when you click the expand button.
Or you could look at this answer. And then, like the code above, just load that one cell that you have specified with that NIB and load the rest the way you would normally.
You can implement the tableview delegate methods to set the height for the cell which needs to expand. Add some condition check in heightForRow method and when user taps on button, change the condition to increase the height. When table is reloading it will call this method and will reload cell with bigger height.