Method to Display Cell Again in UITableViewController - iphone

Which method should I use in order to display a cell again in a UITableViewController?

If your data has been updated you can refresh the view by sending the reloadData message to your tableView:
[myTableView reloadData];
Apple's UITableView reference

If you want to reload specific cells, use UITableView's reloadRowsAtIndexPaths:withRowAnimation: method. For example, if you want to reload the cell at row 20 in section 0 and the cell at row 4 in section 2 without an animation:
[cell reloadRowsAtIndexPaths:[NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:20 inSection:0],
[NSIndexPath indexPathForRow:4 inSection:2],
nil]
withRowAnimation:UITableViewRowAnimationNone];
If you want to reload all the cells in the table view, then use UITableView's reloadData method (but be aware of the performance implications):
[tableView reloadData];
Alternatively, if you just want to redraw a cell (rather than reloading it in order to update its information), you can use UIView's setNeedsDisplay method:
[[cell view] setNeedsDisplay];

Related

tableview cell for Row at index path Query

i want to call table view cell for row at index path explicitly outside.can any one help me out.i have called using [table view object Cell for Row at index path];
Simple reload the table view by default table delegate methods will fire.
[self.tableview1 reload];
If you want to refresh the particular cell just use this :
[self.tableView1 beginUpdates];
[self.tableView1 reloadRowsAtIndexPaths:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView1 endUpdates];

UITableview reload SectionHeader but not cells in section

I have a tableview where I want to reload (and change the height of) just the sectionHeader but not the cells inside this section. The reason I want to do this is because I use the fade animation on the header, like so:
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]
withRowAnimation:UITableViewRowAnimationFade];
But at the same time I am adding a cell in that section with
[self.tableView insertRowsAtIndexPaths:
#[[NSIndexPath indexPathForRow:0 inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
I'd like to be able to keep the UITableViewRowAnimationRight for the cell that is being added, but when I reload the Section, the fade animation gets applied to the whole section. Is there any way to just reload the sectionHeader, and not the cells in the section?
Just create 2 separate brackets of
[tableView beginUpdates];
[tableView endUpdates];
for the two insertions / changes.

Change an image in a UITableViewCell without reloading cell

I'm writing an iPhone app with a UITableView as the primary user interface. Each section consists of two rows, a header and the body. When the user clicks on the header, I remove the second row by changing the numberOfRowsInSection value:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
cbwComponent *comp = [_componentController objectInListAtIndex:section];
if([comp hasContentsView] && !comp.contentsHidden){
return 2;
}else
return 1;
}
When the user selects the header, I'm using the following code:
comp.contentsHidden = YES;
[self.tableView beginUpdates];
NSArray *deleteIndexPaths = [[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:1 inSection:indexPath.section], nil];
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
It's working great, with a nice smooth fade effect. The problem is, I'm trying to add an indicator in the header cell (row 0) that changes when it's clicked on. To change that image I have to refresh the top row as well as the second row, which makes the transition look bad (well, not nearly as smooth). Is there a way to change the image in a UITableViewCell without refreshing the cell?
Thanks
EDIT: I figured it out! You can maintain the smooth transition as long as you reload that first row before you make the change to the second row. It has to be called inside of [tableView beginUpdates];
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:0 inSection:indexPath.section], nil] withRowAnimation:UITableViewRowAnimationNone];
...
[self.tableView endUpdates];
Did the trick.
You could also subclass a tableview cell and implement a view transition in it that can be called from your view controller. You could then call that without having to reload the cell.
[(YourCustomCell*)[tableView cellForRowAtIndexPath:indexPathOfYourCell] fadeInIndicator];

Reload specific UITableView cell in iOS

I have a UITableView. I want to update the table data based on selection made. Right now I use [mytable reloadData]; I want to know if there is any way where I can just update the particular cell which is selected. Can I modify by using NSIndexPath or others? Any suggestions?
Thanks.
For iOS 3.0 and above, you just have to call :
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
To reload row 3 of section 2 and row 4 of section 3 for example, you'll have to do this :
// Build the two index paths
NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:3 inSection:2];
NSIndexPath* indexPath2 = [NSIndexPath indexPathForRow:4 inSection:3];
// Add them in an index path array
NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, indexPath2, nil];
// Launch reload for the two index path
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
You can also get a reference to the UITableViewCell object and change its labels, etc.
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = #"Hey, I've changed!";
I think you're looking for this method of UITableView:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

UITableViewCell's textLabel.text is being partially substituted by ellipsis

I have a UITableView with several UITableViewcells (UITableViewCellStyleSubtitle). When the user taps on one of cells, I push a detail VC that allows the user to change the text of the cell. When I pop this ViewController, the text on the cell appears abbreviated with an ellipsis:
Before:
After:
After changing the text to "Wartyrl" and popping the detail VC.
If I tap on any other cell, the ellipsis disappears and the correct text is displayed. What might be causing this?
This is the code that changes the text of the cell (via a delegate method):
#pragma mark - FRREditTaskViewControllerDelegate
-(void) editTaskViewController:(FRREditTaskViewController *)sender
didChangeNameForTask:(FRRFlatTask *)aTask{
NSIndexPath *idx = [NSIndexPath indexPathForRow:[self.pendings indexOfObject:aTask] inSection:0];
[self.tableView cellForRowAtIndexPath:idx].textLabel.text = aTask.name;
}
BTW, this code is called before popping the detail VC and while the UITableViewController is still hidden. I don't know if this is relevant.
When the cell is created, the UILabel is only large enough to handle the initial text (it doesn't dynamically resize). Calling [self.tableView reloadData] after changing the text (end of your didChangeNameForTask method) should make it display properly.
You can call [cell.textLabel sizeToFit].
In many cases it's cleaner to instead update your internal data and call reloadRowsAtIndexPaths:withRowAnimation:. That way you don't have so many pieces monkeying with the implementation details of the cell (when you change your mind on how to lay it out). It also ensures that your real data matches the cell.
Even better in most cases is to create a UITableViewCell subclass called TaskTableViewCell. You hand it a Task and it observes the Task with KVO, managing its own layout (including calling sizeToFit when needed). That way you don't need delegate methods to tell you when it updates. When the task changes, the cell automatically updates itself. This moves all the layout issues into the cell class and out of the datasource.
It seems that the textLabel hesitates to resize its width. If its too adamant to change, just reload the tableView directly using [tableView reloadData].
If you don't want to reload the entire tableView, you can reload just a particular cell like that following.
NSIndexPath *idx = [NSIndexPath indexPathForRow:[self.pendings indexOfObject:aTask] inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:idx] withRowAnimation:UITableViewRowAnimationFade];
This will show a nice fade animation when changing the textLabel's text of the cell.
-(void) editTaskViewController:(FRREditTaskViewController *)sender
didChangeNameForTask:(FRRFlatTask *)aTask{
NSIndexPath *idx = [NSIndexPath indexPathForRow:[self.pendings indexOfObject:aTask] inSection:0];
UITableViewCell *thiscell=[self.tableView cellForRowAtIndexPath:idx];
thiscell.textLabel.text =[nsstring stringwithFormat:#"%#",aTask.name];
[self.tableView reloadRowsAtIndexPaths: [NSArray arrayWithObject:idx] withRowAnimation:NO];//if u dont want to use reload data then use like this or use
//- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
}