This might be a simple question. HELP with Resetting UITableViewCells
I have a serious doubt. It may开发者_如何学编程 be simple, but I need some help with this.
I have a view (view1) and I navigate to (view2). There is a tableView in View 2 with some textFields (added as a SubView) , and I add some data to the textFields in the UITableViewCells.
I press the back button, and I go back to view 1.
If I navigate again to view 2, the textFields are in the exact same state as I had left it before. I want it to be nil, and show the placeholders in them. How do I make the textFields nil again without disrupting all the other data ?
I used NSUserDefaults in view 1 to let view 2 know that I am navigating. But ... the method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
and viewDidLoad
does not seem to be called again. Only if it is called again, I can make the textFields inside the uitableViewCells nil
.
Could someone tell me how I can call the tableViewCells everytime a navigate to view2 ?
To get your textFields to return to their original state, you'd be best off using some logic in the viewDidDisappear
method. In the most basic form, whenever the view disappears, you'll find the textField
instances (by either having direct references or by searching the tableView subviews) and sending textField.text = @"";
to each. This will clear the text out. If you need to store any of the text, you can, before clearing it, call something like NSString *myText = textField.text;
and do what you need with it, as well as do any other checks or storage before you finish with the view
I cannot believe I missed this. I do not know if I should delete this question...
- I used a simple
[tableView reloadData]
; - Used it in
viewDidAppear
;
These two simple things did the trick !
精彩评论