开发者

Clearing a tableview's contents when back button pressed

I have a simple iPhone app based on a navigation controller. There are two view controllers, VC1 and VC2, both with table views. VC2 also has a custom table cell. When a user selects a row in VC1, VC2 is pushed on to the stack. When the user selects the back button it's removed. Typical navigation stuff.

The problem I have is that the data in the cells in VC2 persists when the back button is pressed, so that when the user selects a different ro开发者_JAVA百科w in VC1, VC2 is pushed back on to the stack with the 'old' data in the cells, before the methods in VC2 reload the data.

I want to make sure that the data in the table in VC is removed every time the back button is pressed. I've tried releasing the tableview using viewWillDisappear, but it's not working. What's the recommended way of dealing with this situation? I've looked at the docs but it's not obvious (to me at least).


Try out this code snippet in viewWillDissapear or dealloc method.

if(yourTableViewCellObject) [yourTableViewCellObject release];
if(yourTableViewCellObject) yourTableViewCellObject=nil;

This might work.


I've used this technique several times since I asked the original question. As I mentioned in my comment to @Aditya, I've found that the easiest way to deal with this is to use viewWillDisappear to hide the tableview with the 'old' data, and when the user navigates back to the page, wait until the 'new' data is loaded into the table before making the tableview visible again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜