开发者

Problem while removing UItableviewcell subviews in iphone development

i am using following code for removing subviews from UItableviewcell to clear out previous subviews before adding new ones

if ([cell.contentView subviews]) {

   for (UIView *subview in [cell.contentView subviews]) {

    [subview removeFromSuperview];
    }
}

problem here is that one of the subviews is an UIImageView object and because of which after removing these imageview (subviews) my applicat开发者_运维百科ion crashes. I cannot even keep it as it is as multiple Imageviews stacking makes application heavier and application eventually throws memorylevel warnings and crashes.

Thanks in advance


You should NOT remove all subviews like that. You don't know where they came from. Instead (if you must remove the subviews) keep an NSMutableArray of all the subviews you add. Then, when you want to remove them, just iterate through that list and call removeFromSuperview, then clear your array.

When you don't create a view, you shouldn't remove its subviews. I've been burned by that before. You don't know which ones you added, and which ones were added before. You can easily remove things like scroll bars, disclosure indicators, and other important things.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜