这两天借助了block来完成一些功能,有感而发。。。
block基础请看戳这里
一、基本使用:
在 Define.h 文件中
//textview block ---- about me
@property (nonatomic, strong) void(^endEditTextViewCell)(UITableViewCell* cell, MsgInputFieldView* textView);
@property (strong, nonatomic) void (^completionHandler)(NSArray *);
在 Defind.m 文件中
<pre name="code" class="objc">- (id)initWithSelectedValue:(NSArray *)selectedValue
completionHandler:(void(^)(NSArray *selected))completionHandler
{
self.completionHandler = completionHandler;
}
</pre><pre name="code" class="objc">代码 chao.
- (void)textViewDidEndEditing:(UITextView *)textView {
self.endEditTextViewCell(self,_aboutMeTextView);
}
<pre name="code" class="objc"><span style="font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="objc">代码 xxx.
- (void)doneClick:(id)sender{
if(_completionHandler != nil)
self.completionHandler(tagList.selectedItem);
[self dismissViewControllerAnimated:YES completion:nil];
}
在 implement.m 文件中
<pre name="code" class="objc">Define *define = [[Define alloc] init];
<span style="font-family: Arial, Helvetica, sans-serif;">[defind setEditingTextViewCell:^(UITableViewCell *editingcell, MsgInputFieldView *textView) {</span>
//start edit //do something as you like
<span style="white-space:pre"> </span>//当上边的 代码 chao被执行,就会回调这里的代码
}];
void (^completionHandler</span>)(NSArray *) = ^(NSArray *selected) {
//start edit
//do something as you like<pre name="code" class="objc"><span> </span>//通过下方初始化的方式传入block,代码 xxx 被执行,这里的代码会被回调
};
LabelHobbyViewController *hobbyController = [[LabelHobbyViewController alloc] initWithSelectedValue:hobbyData completionHandler:completionHandler<span style="font-family: Arial, Helvetica, sans-serif;">];</span>
</pre><pre name="code" class="objc">