开发者

Handling NSArray and NSMutableArray

开发者 https://www.devze.com 2023-03-18 16:17 出处:网络
I\'m working with the MKMapView and I\'m using some arrays to handle the title of points on the map NSString *mapTitles = @\"title1^^title2^^title3^^title4\";//this data changes between views

I'm working with the MKMapView and I'm using some arrays to handle the title of points on the map

NSString *mapTitles = @"title1^^title2^^title3^^title4";//this data changes between views
NSArray * titlesArray = [mapTitles componentsSeparatedByString: @"^^"];
NSMutableArray * maptitle开发者_StackOverflow中文版 = [NSMutableArray arrayWithCapacity:[titlesArray count]]; 
[maptitle addObjectsFromArray:titlesArray];

When a user navigates to another page I want to clear the NSMutableArray so that when they come back to the map I can refresh it with new data. However as the NSMutableArray is getting populated by an NSArray which I can't clear, how do I ensure that the NSMutableArray only gets populated by new data as opposed to something that the NSArray may have kept from the previous view?.

Is it simply a case of releasing the NSArray, for example in viewWillDisappear?

Thanks


You can still clear the mutable array itself:

[mapTitle removeAllObjects];

You shouldn't release the titlesArray because it's autoreleased.

0

精彩评论

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

关注公众号