当点击单元格时 调用block传值的属性
#import <UIKit/UIKit.h>
@interface JSONExplorerViewController : UIViewController
@property (nonatomic, copy) void (^completionBlock)(NSString *jsonURL);
@end
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *fileURL = self.jsonFiles[indexPath.row];
//为所获取到的 本地文件路径 末尾拼接一个 " \ "
//使用字符串替换可以事后弥补:[jsonString stringByReplacingOccurrencesOfString:@"\\" withString:@""];
NSArray *components = [fileURL componentsSeparatedByString:@"/"];
if (self.completionBlock) {
//通过当前去调用 URL block传值的 属性
self.completionBlock(components.lastObject);
//所点击的 单元格行内容 并输出 通过文件路径,且获取到的最后一个对象元素
NSLog(@"\n===n%@===\n====%ld\n",components.lastObject,(long)indexPath.row);
}
}
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStyleDone target:self
action:@selector(_closePressed)];
- "关闭“ 触发的方法 —— (不返回 任何 数据即可。 写 nil )
- (void)_closePressed {
if (self.completionBlock) {
self.completionBlock(nil);
}
}
网友评论