{"action":"created","issue":{"url":"https://api.github.com/repos/appcelerator/titanium_mobile/issues/7992","repository_url":"https://api.github.com/repos/appcelerator/titanium_mobile","labels_url":"https://api.github.com/repos/appcelerator/titanium_mobile/issues/7992/labels{/name}","comments_url":"https://api.github.com/repos/appcelerator/titanium_mobile/issues/7992/comments","events_url":"https://api.github.com/repos/appcelerator/titanium_mobile/issues/7992/events","html_url":"https://github.com/appcelerator/titanium_mobile/pull/7992","id":153460782,"number":7992,"title":"[TIMOB-23341] Exception on iPhone: no row found for index. ","user":{"login":"TiBaharroth","id":17764429,"avatar_url":"https://avatars.githubusercontent.com/u/17764429?v=3","gravatar_id":"","url":"https://api.github.com/users/TiBaharroth","html_url":"https://github.com/TiBaharroth","followers_url":"https://api.github.com/users/TiBaharroth/followers","following_url":"https://api.github.com/users/TiBaharroth/following{/other_user}","gists_url":"https://api.github.com/users/TiBaharroth/gists{/gist_id}","starred_url":"https://api.github.com/users/TiBaharroth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TiBaharroth/subscriptions","organizations_url":"https://api.github.com/users/TiBaharroth/orgs","repos_url":"https://api.github.com/users/TiBaharroth/repos","events_url":"https://api.github.com/users/TiBaharroth/events{/privacy}","received_events_url":"https://api.github.com/users/TiBaharroth/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/appcelerator/titanium_mobile/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/appcelerator/titanium_mobile/labels/community","name":"community","color":"fbca04"},{"url":"https://api.github.com/repos/appcelerator/titanium_mobile/labels/ios","name":"ios","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-05-06T14:19:37Z","updated_at":"2016-06-16T16:36:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/appcelerator/titanium_mobile/pulls/7992","html_url":"https://github.com/appcelerator/titanium_mobile/pull/7992","diff_url":"https://github.com/appcelerator/titanium_mobile/pull/7992.diff","patch_url":"https://github.com/appcelerator/titanium_mobile/pull/7992.patch"},"body":"**JIRA:** https://jira.appcelerator.org/browse/TIMOB-23341\r\n\r\nFix the bug : insert in the insertRowBefore and insertRowAfter\r\n```objc\r\nif (![NSThread isMainThread]) {\r\n        TiThreadPerformOnMainThread(^{[self insertRowBefore:args];},YES); // YES = wait for the operation to complete on the main thread !!!\r\n        return;\r\n}\r\n```\r\nExplaination : \r\n'The problem here is actually very simple, but it took me few hours to find this out. JS engine itself runs in async context, which means that if one is inserting multiple rows in JavaScript (e.g. in a loop) using insertRowBefore then the obj-c code behind this does the work in async (non-UI) thread. I think the reason the ENSURE_UI_THREAD(insertRowBefore,args); line was commented is becase the actual action happens in UI thread anyway - see how [table dispatchAction:action] works (TiUITableViewProxy.m around line 535).\r\n\r\nThe code that checks the row indexes and verifies against existing list still runs asynchronously and thus if you run inserting rows in loop this can have unpredictable results because the list might not yet be updated, etc.. So the solution here is to synchronize the insertion and wait for it’s completion. Finally the commented code mentioned by Dave Cadwallader should be replaced with this:'\r\n\r\nFrom https://archive.appcelerator.com/question/129708/obj-c-fix-for-error-on-tableview-insertrowbefore--insertrowafter"},"comment":{"url":"https://api.github.com/repos/appcelerator/titanium_mobile/issues/comments/226541366","html_url":"https://github.com/appcelerator/titanium_mobile/pull/7992#issuecomment-226541366","issue_url":"https://api.github.com/repos/appcelerator/titanium_mobile/issues/7992","id":226541366,"user":{"login":"build","id":125029,"avatar_url":"https://avatars.githubusercontent.com/u/125029?v=3","gravatar_id":"","url":"https://api.github.com/users/build","html_url":"https://github.com/build","followers_url":"https://api.github.com/users/build/followers","following_url":"https://api.github.com/users/build/following{/other_user}","gists_url":"https://api.github.com/users/build/gists{/gist_id}","starred_url":"https://api.github.com/users/build/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/build/subscriptions","organizations_url":"https://api.github.com/users/build/orgs","repos_url":"https://api.github.com/users/build/repos","events_url":"https://api.github.com/users/build/events{/privacy}","received_events_url":"https://api.github.com/users/build/received_events","type":"User","site_admin":false},"created_at":"2016-06-16T16:36:50Z","updated_at":"2016-06-16T16:36:50Z","body":"Can one of the admins verify this patch?"}}
{"actor":{"display_login":"build"}}