开发者

UITableView scrolling issue after memory warning

开发者 https://www.devze.com 2023-01-18 09:12 出处:网络
I created a UITableView similar to the iOS address book that allows you to pick an image on one row and and there are additional custom cells that have text fields for entering data.I run into this pr

I created a UITableView similar to the iOS address book that allows you to pick an image on one row and and there are additional custom cells that have text fields for entering data. I run into this problem only after loading a large image and get a memory warning in the console:

Received memory warning. Level=1

I load the image using the UIImagePickerController in a modal view.

So, when the memory warning occurs, my parent tableviewcontroller does a viewDidUnload, which is empty:

- (void)viewDidUnload { }

Once I close the modal view (choosing the image), the tableview reloads data and everything appears fine...However, scrolling does not work properly. The behavior is very odd: The scrolling will not stay past a certain point. I can literally pull the scrolling down all the way, but as soon as I release, the scrolling bounces back up and hides the bottom fiew cells (which appear normal).

For the life of me I cannot figure out what is going on, why this only occurs after a memory warning.

This is only happening on my iPhone (testing with iPhone 4). This further lea开发者_运维百科ds me to believe the memory warning is probably the root of my problem.


I have a work around. Before you display the modal view you should dismiss the keyboard and wait until its dismissed.


Everything you set up in [loadView] or [viewDidLoad] should be cleaned up in [viewDidUnload]. And the other way around: everything you destroy in [viewDidUnload] should be re-created and re-initialized in [loadView] or [viewDidLoad].

You should treat it as a secondary init/dealloc sequence.


Setting the -(void)viewDidUnload; to empty is definitely wrong in that context as there should be at least call to [super viewDidUnload]; otherwise you'll have two tables in the view(or even more) because the controller will keep creating them inside of -(void)loadView;

0

精彩评论

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

关注公众号