{"id":151,"date":"2006-07-07T08:55:01","date_gmt":"2006-07-07T16:55:01","guid":{"rendered":"http:\/\/www.corbinstreehouse.com\/blog\/?p=151"},"modified":"2018-10-31T10:16:18","modified_gmt":"2018-10-31T17:16:18","slug":"nsoutlineview-reloaddata-and-crashes-in-reloaddata","status":"publish","type":"post","link":"https:\/\/www.corbinstreehouse.com\/blog\/2006\/07\/nsoutlineview-reloaddata-and-crashes-in-reloaddata\/","title":{"rendered":"NSOutlineView: reloadData and crashes in reloadData"},"content":{"rendered":"<p id=\"top\" \/>A note to NSOutlineView Cocoa programmers: It has never been safe to call reloadData while an outlineView is doing a reloadData. What the heck does that mean? Well, if you call reloadData, a whole bunch of delegate\/datasource methods will be called, such as outlineView:numberOfChildrenOfItem:, outlineView:isItemExpandable:, etc. Well, if in those delegate methods you accidentally call reloadData <b>again<\/b>, bad things can happen. Specifically, you will probably get a crash in NSOutlineView. More often than not, this is done by an accidental side effect, but it is something to be aware of. On Leopard, I will make NSOutlineView more resilient to this case, and not crash. On Tiger, you can fix it yourself, if you think it is (or may) affect you. Here is the general recipe:<\/p>\n<p>1. Subclass NSOutlineView, and add an iVar that looks like:<\/p>\n<pre class=\"code\">\n   BOOL _isReloading;\n<\/pre>\n<p>2. Override reloadData and make it look something like this:<\/p>\n<pre class=\"code\">\n- (void)reloadData {\n    if (!_isReloading) {\n       _isReloading = YES;\n       [super reloadData];\n       _isReloading = NO;\n   } else {\n       [self performSelector:@selector(reloadData) withObject:nil afterDelay:0];\n   }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A note to NSOutlineView Cocoa programmers: It has never been safe to call reloadData while an outlineView is doing a reloadData. What the heck does that mean? Well, if you call reloadData, a whole bunch&#8230; <a class=\"read-more\" href=\"https:\/\/www.corbinstreehouse.com\/blog\/2006\/07\/nsoutlineview-reloaddata-and-crashes-in-reloaddata\/\">[read more]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,6,1],"tags":[63,130,72],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-apple","category-cocoa","category-general","tag-cocoa","tag-objc","tag-programming"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":1,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":5333,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions\/5333"}],"wp:attachment":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}