Get the solution myself. Although the ideal solution is to put the loop in another thread, it is too difficult to handle the thread safety things. An alternative solution is to execute the code in a delayed way. (like shown below)
-(IBAction)upload:(id)sender {
NSOpenPanel *uploadPanel = [NSOpenPanel openPanel];
if ([uploadPanel runModal] == NSOKButton) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 100), dispatch_get_main_queue(), ^(void){
for (int i = 0; i < 10000; i++) {
NSLog(@"%d",i);
}
});
}
}