您的位置:首页 > 移动开发 > IOS开发

iOS方法作为属性传递

2015-12-25 17:41 381 查看
iOS中方法作为属性或者是参数进行传递,下边我是以代理方法为例。

.h中的代码让代理方法作为一个属性

@property(nonatomic,assign)SEL delegateSelect;

.m中的代码让delegate调用这个传过来的代理方法  传值用withObject:一个对象传递

                #define SuppressPerformSelectorLeakWarning(Stuff) \

                do { \

                _Pragma("clang diagnostic push") \

                _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \

                Stuff; \

                _Pragma("clang diagnostic pop") \

                } while (0)

             if ([self.delegate
respondsToSelector:self.delegateSelect]) {

                 NSMutableDictionary* dict = [[NSMutableDictionary
alloc]
init];

                 [dict setValue:[NSNumber
numberWithFloat:oldCoordinate.longitude]
forKey:@"longitude"];

                  [dict setValue:[NSNumber
numberWithFloat:oldCoordinate.latitude]
forKey:@"latitude"];

                 SuppressPerformSelectorLeakWarning([self.delegate
performSelector:self.delegateSelect
withObject:place.name
withObject:dict]);

             }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: