Solution: ios UITableView content cannot be refreshed

Source: Internet
Author: User

When using UITableView, If you modify some UITableViewCell-related content in UITableView in another view, you need to re-load the modified data when calling popViewController to return the UITableView, UITableViewCell data is not reloaded by default.

In general, we can solve this problem by adding [self. tableView reloadData] To the viewWillAppear function in the UITableViewController. m file. This function will call the cellForRowAtIndexPath method to reload the data of UITableViewCell.

However, we sometimes find that the content of UITableViewCell cannot be refreshed even if reloadData is called. At this time, it is very likely that the order of the popViewController you call is incorrect, that is, the function of popViewController is called too early, because after the function of popViewController is called, the compiler will start from self. in the navigationController stack, obtain the top-level ViewController (UITableViewController) and display its view. This process calls functions on these initial display interfaces, such as the ViewWillAppear function, if you modify some attributes in UITableView only after popViewController, although the value of the attributes can be changed, the UITableView is displayed, therefore, the new property values cannot be displayed on the interface, resulting in the illusion that the content is not refreshed.

Solution:

Call the popViewController method after modifying the attribute value. See the following code (1 ). In addition, to obtain the UITableViewController, because the current ViewController has not been pop up yet, you need to take the next Controller at the top of the stack, see (2 ).

NSArray * allControllers = self. navigationController. viewControllers;

RenewTableViewController * parent = [allControllers objectAtIndex: [allControllers count]-2]; // (2)

Parent. test = @ "test ";

[Self. navigationController popViewControllerAnimated: YES]; // (1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.