JSPatch下发笔记6
2017-03-06 本文已影响30人
anny_4243
OC代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
[NSImagePicker showImagePickerFromViewController:self allowEditing:YES finishAction:^(UIImage *image) {
if (image) {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[[NSNetworking sharedManager]uploadimagesWithArray:@[image] success:^(id response) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
NSDictionary *parameters = @{@"userDesId":kAccountInfo.desId,@"headPhoto":response[@"items"][0]};
[[NSNetworking sharedManager]get:API_NEISHA_MODIFY parameters:parameters success:^(id responseModel) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[WKProgressHUD popMessage:@"修改成功" inView:self.view duration:HUD_DURATION animated:YES];
_userHeaderUrl = [response objectForKey:@"items"][0];
[kTabbar.topViewControllers[4] performSelector:@selector(reloadViews)];
[self.tableView reloadData];
} failure:^(NSString *error,int errorCode) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[WKProgressHUD popMessage:error inView:self.view duration:HUD_DURATION animated:YES];
}];
} failure:^(NSString *error,int errorCode) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[WKProgressHUD popMessage:error inView:self.view duration:HUD_DURATION animated:YES];
}];
}
}];
}
}
JS代码:
require('NSImagePicker,MBProgressHUD,NSNetworking,WKProgressHUD,AccountManager,CLNNTabBarController');
defineClass('PersonalViewController', {
tableView_didSelectRowAtIndexPath: function(tableView, indexPath) {
if (indexPath.section() == 0) {
var weakSelf = __weak(self);
NSImagePicker.showImagePickerFromViewController_allowEditing_finishAction(self, YES, block('UIImage*', function(image) {
if (image){
MBProgressHUD.showHUDAddedTo_animated(weakSelf.view(), YES);
NSNetworking.sharedManager().uploadimagesWithArray_success_failure([image], block('id', function(response) {
MBProgressHUD.hideAllHUDsForView_animated(weakSelf.view(), YES);
var arr = response.objectForKey("items");
var parameters = {
"userDesId": AccountManager.getInstance().accountInfo().desId(),
"headPhoto": arr.objectAtIndex(0)
};
NSNetworking.sharedManager().get_parameters_success_failure("/api/user/modifyUserMsg", parameters, block('id', function(responseModel) {
MBProgressHUD.hideAllHUDsForView_animated(weakSelf.view(), YES);
WKProgressHUD.popMessage_inView_duration_animated("修改成功", weakSelf.view(), 1.0, YES);
_userHeaderUrl = arr.objectAtIndex(0);
weakSelf.setValue_forKey(_userHeaderUrl, "_userHeaderUrl");
CLNNTabBarController.sharedInstance().topViewControllers().objectAtIndex(4).performSelector("reloadViews");
weakSelf.tableView().reloadData();
}), block('NSString*,int', function(error, errorCode) {
MBProgressHUD.hideAllHUDsForView_animated(weakSelf.view(), YES);
WKProgressHUD.popMessage_inView_duration_animated(error, weakSelf.view(), 1.0, YES);
}));
}), block('NSString*,int', function(error, errorCode) {
MBProgressHUD.hideAllHUDsForView_animated(weakSelf.view(), YES);
WKProgressHUD.popMessage_inView_duration_animated(error, weakSelf.view(), 1.0, YES);
}));
}
}));
}
},
});
总结:
1.不可变数组表示方法,OC:@[image],JS:[image]。
2.字典取值方法:OC:response[@"items"][0],JS:response.objectForKey("items").objectAtIndex(0)
3.JS 私有变量block内赋值: weakSelf.setValue_forKey(_userHeaderUrl, "_userHeaderUrl");
4.选择器表示方法:
OC:performSelector:@selector(reloadViews)
JS:performSelector("reloadViews")