Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Specific cells in a tableView without calling reloadData

I have an app in which I have a UITableview with custom cells and headers. The cells have an inputView so when selected they become first responder and allow the user to input data. I want to be able to update the visible TableViewCell and header information on the fly while the user is changing it.. easy, just call [tableview reloadData]; .. Unfortunately this causes the inputview to resign first responder and hide itself.

Is there any way that I can get a reference to the cell itself inside the UITableview so that I can just change the text property? (cellForRow:atIndexPath: returns a new object with the same properties so doesn't work) It seems like the only easy solution may be to store a reference the cells in a dictionary each time a cell is populated, not really the ideal solution.

cellForRowAtIndexPath is literally just

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *orderCell;
    static NSString *productCellIdentifier = @"ImageDetailCellIdentifier";
    orderCell = [self.tableView dequeueReusableCellWithIdentifier:productCellIdentifier forIndexPath:indexPath];

//set a bunch of properties orderCell.blah
    return orderCell;
}
like image 685
user2877496 Avatar asked Mar 10 '26 23:03

user2877496


2 Answers

According to UITableView documentation, -cellForRowAtIndexPath: returns an object representing a cell of the table or nil if the cell is not visible or indexPath is out of range.

That is also how I remember it. I don't think your observation is correct that it returns a new object. If the cell is visible you will get hold of it.

like image 163
svena Avatar answered Mar 12 '26 13:03

svena


[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; ///as your choice in animation
[tableView endUpdates];

or else

 [tableView beginUpdates];
// do some work what ever u need
 [tableView endUpdates];
like image 34
Anbu.Karthik Avatar answered Mar 12 '26 12:03

Anbu.Karthik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!