Reputation: 2649
is there any way to change value of a cell after it is loaded? actually i am having one textfield in the table and after inserting the value of the same,i need to do some numeric operations on the textfield value and the value calculater need to display on the lable that in in the next cell.
So how can i get the same result?any idea?
Thanks in advance.
Upvotes: 2
Views: 2266
Reputation: 18670
For what you are trying to do, your best bet is to make your view controller a <UITextFieldDelegate>
, set your cell's text field delegate to self, and then implement the textFieldDidEndEditing: delegate method.
Change your interface file to adopt the protocol
@interface YourViewController : UIViewController <UITextFieldDelegate>
Then set the view controller as the delegate of your relevant UITextField(s)...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
yourCustomCell.yourTextField.delegate = self
}
And finally implement
- (void) textFieldDidEndEditing:(UITextField *)textField.
This method will get called everytime the user finishes editing your UITextField, and as it passes a reference to it you can access it's values, do any validation you may need and assign it back to the textfield.
Upvotes: 1
Reputation: 10090
There are several ways to update a cell in a UITableView
.
1) Call the table view method reloadRowsAtIndexPaths:withRowAnimation:
. This will trigger a call to the delegate method tableView:cellForRowAtIndexPath:
. If you have a data source that you are updating this would be a good way to update a cell.
NSIndexPath *indexPathOfUpdatedCell = ...
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPathOfUpdatedCell] withRowAnimation:UITableViewRowAnimationFade];
2) It is also possible to update the cell directly. You can use cellForRowAtIndexPath:
.
NSIndexPath *indexPathOfUpdatedCell = ...
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPathOfUpdatedCell];
cell.textLabel.text = @"new value";
To create an index path for a specific row and section it is possible to use indexPathForRow:inSection
.
NSUInteger row = ...
NSUInteger section = ...
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
Upvotes: 4