1.这个方法是在cell中用的(比如我在cell中写了一个button的点击方法,我想在点击方法中找到cell的indexPath并通过通知传出去,在其他任何地方用)
UITableView *tableView;
float Version=[[[UIDevice currentDevice] systemVersion] floatValue];//(设备判断)
if(Version>=7.0){
tableView = (UITableView *)self.superview.superview;
}else{
tableView=(UITableView *)self.superview;
}
NSIndexPath *indexPath= [tableView indexPathForCell:self];
NSNotification * notification = [NSNotification notificationWithName:@"clickNumber" object:self userInfo:@{@"value":[NSString stringWithFormat:@"%ld",(long)[indexPath row]]}];
[[NSNotificationCenter defaultCenter] postNotification:notification];
2.接值
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickNumber:) name:@"clickNumber" object:nil];
- (void)clickNumber:(NSNotification *)notification{
NSString *string = [notification valueForKey:@"userInfo"][@"value"];
NSLog(@"%@",string);
}