Solution to the UITableView content of iOS can not refresh the method

Source: Internet
Author: User

In the process of using UITableView, if you modify the contents of some UITableViewCell in the UITableView in another view, When the call Popviewcontroller returns this UITableView, the modified data will need to be reloaded, and the UITableViewCell data will not be reloaded by default.

In general, we can solve this function by adding [Self.tableview Reloaddata] to the Viewwillappear function in the uitableviewcontroller.m file. This function will call Cellforrowatindexpath this method, thus reloading the UITableViewCell data.

But sometimes we find that the contents of UITableViewCell cannot be refreshed even if the reloaddata is invoked. This is probably because of the error in the Popviewcontroller order you called, which is too early to call Popviewcontroller, because when you call Popviewcontroller this function, The compiler gets the topmost viewcontroller from the Self.navigationcontroller stack (the uitableviewcontroller here) and displays its view, This process will call the Viewwillappear function, such as the initial display interface functions, if you popviewcontroller after the uitableview of some of the properties of the contents of the changes, although can change the value of the property content, But since the UITableView has been shown, the new attribute values are not displayed in the interface, thus creating an illusion of not refreshing the content.

Workaround:

Place the Popviewcontroller method after the modified property value, as shown in the following code (1). In addition, to get Uitableviewcontroller, because at this time the current Viewcontroller has not been pop out, so to take the top of the stack of the next controller, see (2).

Nsarray *allcontrollers = self.navigationController.viewControllers;

Renewtableviewcontroller *parent = [allcontrollers objectatindex:[allcontrollers count]-2]; (2)

parent.test=@ "Test";

[Self.navigationcontroller Popviewcontrolleranimated:yes]; (1)

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.