Last active
March 9, 2019 08:51
-
-
Save chance395/67170d9fd172e06e3dda9cfaea0461b5 to your computer and use it in GitHub Desktop.
#ios_block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.表达方式 | |
申明: (返回值类型)(^block名)(参数列表); | |
变量形式: ^(形参列表){ | |
codes... | |
} | |
tydef: typedef (返回值类型)(^block名)(参数列表); | |
函数中: | |
1.第一种边定义边使用,当成一段函数直接调用 | |
void(^UpdateUIBlock)(void) = [^{ | |
UITableView * tableView = self.contactsListView.tableView; | |
[UIView setAnimationsEnabled:NO]; | |
[tableView reloadData]; | |
[UIView setAnimationsEnabled:YES]; | |
} copy]; | |
[NSThread isMainThread] ? updateUIBlock() :dispatch_async(dispatch_get_main_queue(), updateUIBlock); | |
2.返回一个回调参数,这种必须对Block赋值,一种是下面,还有一种是setter | |
@property (nonatomic, strong) void (^dispath_queueNoParaCompletion)(void); | |
+(void)callMainQueueWithCompletionBlock:(void(^)(void))completionBlock | |
{ | |
if (completionBlock) { | |
self.dispath_queueNoParaCompletion = completionBlock; | |
} | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
!self.dispath_queueNoParaCompletion ? :self.dispath_queueNoParaCompletion(); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment