Animate section footer changes in grouped UITableView - objective-c

I know that you can animate insertions of table view cells and section but sometimes I need to change the footer text to one with a different text or to one that is 'nil'. I need to animate it when a UISwitch is toggled.
Right now I am using [tableView reloadData] but this is ugly and changes the section footer too sudden and without any animations. Apple somehow animates this for example when you turn on Personal Hotspot the section footer is slightly changed and this change is animated.
How can I achieve the same effect?

Assuming you've already written the code in -tableView:titleForFooterInSection: to adjust in response to the UISwitch, you could just send an empty update block to the table view to get it reload with animation.
[self.tableView beginUpdates];
[self.tableView endUpdates];

Related

UITableView not drawing Cells correctly "sometimes"

When my app displays the table, sometimes, it displays ALL the content of the database. but when i try to segue to another VC an return from that VC (Lets say, I added a new entry to the Database), it displays this. if you touch below the "Missing" cells, it segue to the correct entry though...
I've already tried using:
[self.cTableView setNeedsDisplay];
[self.cTableView setNeedsLayout];
or
[self.cTableView beginUpdates];
[self.cTableView endUpdates];
or
[self.cTableView reloadData];
but still to no avail. Is there any way of refreshing the tableview graphically?
I can't post images due to reputations but the image that I'm going to post looks like the TableView gets CUT going down.
Image:
https://dl.dropboxusercontent.com/u/1336061/StackOverflow/Untitled.jpg
Are you re-using your cell correctly?
Check the cells reuse identifier. see that the cells are not being allocated every iteration (in cellForRow delegate).
If the objects that provide data to the "Data Source" of the table change, you might as well need to call:
[table reloadData];
OR
Load the new elements with their indexes (look at the UITableView headers to use the right delegate.

Moving table view cells down without moving tableview's origin

I want to be able to move/shift the group of UITableViewCells in the UITableView downward, without scrolling the tableView, and without moving the entire tableview downward. The desired effect is that there is an amount of whitespace above the table view cells after they're placed in the table view, and when the user scrolls down through the table view, the white space is covered by the cells.
Don't forget that a UITableView is a subclass of UIScrollView.
And that UIScrollView have this property.
contentInset
The distance that the content view is inset from the enclosing scroll view.
#property(nonatomic) UIEdgeInsets contentInset
Discussion
Use this property to add to the scrolling area around the content. The unit of size is points. The default value is UIEdgeInsetsZero.
I don't fully understand what you are trying to do, so I just hope that this is what you are looking for.
After Question was Edited
Add an empty cell where you want it to be and adjust it's size when needed.
You will need to make some try about doing it animated (using insert and reloadCell) or using the reloadData option of the tableView to get the visual you want.
You could use a tableView header and adjust its size. After changing its size, call:
[tableView reloadData];
If you want to animate the size change, try calling:
[tableView beginUpdates];
[tableView endUpdates];
After changing the header's size.
EDIT 1:
As opposed to a table view header, you could use a static cell as mentioned in the other answer. To animate the size change, use the steps above. Change the size in:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

Reloading subview (UICollectionview)

In my ViewController I have four subviews, i.e UITableView, UICollectionView, View with UILabels, and View that displays preview image for that item.
By selecting a row in tableview, I am able to change preview image and all labels. However I can not refresh the UICollectionView data. I tried this solution but it just removes and adds views and that changes the layout and preview image disappears.
All I want to do is refresh UICollectionView contents. Is there any simpler way to do this?
Have you tried [self.collectionView reloadData]; ?
To refresh only a portion of the UICollectionView you could also call this:
[self.collectionView reloadItemsAtIndexPaths:#[indexPath]]
where indexPath is the cell you want to reload. You could include multiple index paths in the array as well. To reload the entire first section you could call this:
NSIndexSet *sections = [NSIndexSet indexSetWithIndex:0];
[self.collectionView reloadSections:sections];
Assuming you have correctly hooked up your UICollectionView to a dataSource (UICollectionViewDataSource), you can call [myCollectionView reloadData] to make your collection view call your dataSource's methods (as below) to refresh itself:
– collectionView:numberOfItemsInSection:
– numberOfSectionsInCollectionView:
– collectionView:cellForItemAtIndexPath:
– collectionView:viewForSupplementaryElementOfKind:atIndexPath:

Table View Checkmark if Task Complete

I'm working in Objective C. I have a UITableViewController with about 25 cells that push to a UIViewController. When the user hits back, I want to see if the user entered the correct data for the given cell. (I have a working bool , we'll call it isCellComplete for now). If isCellComplete is true, I want to add a checkmark as the accessory to the cell. I've been trying to put the test in cellForRowAtIndexPath but that method does not seem to run and refresh the cells everytime the view appears. Anyone have suggestions?
You should look into the UITableView method reloadRowsAtIndexPaths:withRowAnimation:. This is much more elegant than reloading the whole table view. And if you don't want an animation, you can specify UITableViewRowAnimationNone and it will look just like reloadData but be much more efficient.
You should do the check in tableView:cellForRowAtIndexPath: and if the check passes, set the cell's accessory to UITableViewCellAccessoryCheckmark. Then when you tell the table view to reload the appropriate row(s), it'll automatically call tableView:cellForRowAtIndexPath: on the data source and update that cell.
You could just call
[self.tableView reloadData];
in
-(void) viewWillAppear:(BOOL)animated
And that will make cellForRowAtIndexPath be called again when the view appears

Change UITableViewCell frame but didn't work

UITableViewCell *cell = [tableViewController.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
[cell setFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y - 34, cell.frame.size.width, cell.frame.size.height)];
I want to change the frame of table view cell, the code work in some ViewController, but some it doesn't work.
I want to know is there something wrong with it.
thanks a lot.
You cannot have full control on the cell frame, especially on the origin. The table view delegate is asked for a table view cell, but then its position depends on the internal logic of the table view in order to correctly place the cell inside the table view (which is a scroll view subclass). When the displayed portion of the table view is refreshed, the cell position is rearranged and the frame origin is updated.
So while your code is not wrong, it conflicts with some table internal rules you cannot fully control and so the results could unpredictable.
If you want instead to see a visible effect of this change, you can move your frame changer code to another part of the code, e.g. inside the tableView:didSelectRowAtIndexPath:
In such case you can for example touch a cell, call this code and change the cell frame and you will the change immediately. But as soon as you scroll the cell out of the iPhone screen, and then you move back this cell in the screen, you will notice that it will re-appear in its original position.