OC3_选择器
//
// Dog.h
// OC3_选择器
//
// Created by zhangxueming on 15/6/16.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> @interface Dog : NSObject @property (copy)NSString *name;
@property (assign,nonatomic)NSInteger age; - (void)bark:(NSNumber *)count; @end
//
// Dog.m
// OC3_选择器
//
// Created by zhangxueming on 15/6/16.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "Dog.h" @implementation Dog - (void)bark:(NSNumber *)count
{
NSInteger cnt = [count integerValue];
for (NSInteger i=; i<cnt; i++) {
NSLog(@"Wang wang wang ...");
}
} @end
//
// main.m
// OC3_选择器
//
// Created by zhangxueming on 15/6/16.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h>
#import "Dog.h" //函数指针变量 int add(int a, int b)
{
return a+b;
}
//选择器
//运行层次概念
//sel int main(int argc, const char * argv[]) {
@autoreleasepool {
int (*pfunc)(int, int) = add;
NSLog(@"add = %d", pfunc(,)); Dog *xiaoBai = [[Dog alloc] init];
//[xiaoBai bark:[NSNumber numberWithInt:4]]; //1.利用@selector关键字生成选择器
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
//方法一:
//SEL select = @selector(bark:);
//方法二:
//利用方法名的字符串对象生成选择器
SEL select = NSSelectorFromString(@"bark:");
//方法三:
//利用C语言的字符串生成选择器
//SEL select = sel_getUid("bark:"); //获取选择器中保存的方法名
NSLog(@"%s", sel_getName(select));
NSLog(@"%@", NSStringFromSelector(select)); //NSLog(@"%p", select);
//判断对象所在的类是否实现选择器中的方法
if([xiaoBai respondsToSelector:select])
{
//执行选择器中保存的方法
//[xiaoBai performSelector:select withObject:[NSNumber numberWithInteger:10]];
[xiaoBai bark:[NSNumber numberWithInteger:]];
}
#pragma clang diagnostic pop
}
return ;
}
OC3_选择器的更多相关文章
- 前端极易被误导的css选择器权重计算及css内联样式的妙用技巧
记得大学时候,专业课的网页设计书籍里面讲过css选择器权重的计算:id是100,class是10,html标签是5等等,然后全部加起来的和进行比较... 我只想说:真是误人子弟,害人不浅! 最近,在前 ...
- jQuery的61种选择器
The Write Less , Do More ! jQuery选择器 1. #id : 根据给定的ID匹配一个元素 <p id="myId">这是第一个p标签< ...
- 05.LoT.UI 前后台通用框架分解系列之——漂亮的时间选择器
LOT.UI分解系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#lotui LoT.UI开源地址如下:https://github.com/du ...
- CSS 选择器及各样式引用方式
Css :层叠样式表 (Cascading Style Sheets),定义了如何显示HTML元素. 目录 1. 选择器的分类:介绍ID.class.元素名称.符合.层次.伪类.属性选择器. 2. 样 ...
- jQuery学习之路(1)-选择器
▓▓▓▓▓▓ 大致介绍 终于开始了我的jQuery学习之路!感觉不能再拖了,要边学习原生JavaScript边学习jQuery jQuery是什么? jQuery是一个快速.简洁的JavaScript ...
- 谈谈一些有趣的CSS题目(十)-- 结构性伪类选择器
开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...
- JQuery 选择器
选择器是JQuery的根基,在JQuery中,对事件的处理,遍历DOM和AJAX操作都依赖于选择器.如果能够熟练地使用选择器,不仅能简化代码,而且还可以事半功倍. JQuery选择器的优势 1.简洁的 ...
- jq选择器基础
Jquery $代表选择器 使用jq必须要导入jq文件 <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js&qu ...
- 微信小程序中利用时间选择器和js无计算实现定时器(将字符串或秒数转换成倒计时)
转载注明出处 改成了一个单独的js文件,并修改代码增加了通用性,点击这里查看 今天写小程序,有一个需求就是用户选择时间,然后我这边就要开始倒计时. 因为小程序的限制,所以直接选用时间选择器作为选择定时 ...
随机推荐
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 UVa中译题uHuntAlgorithmist Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 Mirror UVa Online Judg ...
- LeetCode: Word Break II [140]
[题目] Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where ...
- Covarience And ContraVariance
using System; using System.Collections.Generic; using System.IO; namespace CovarientAndContraVarient ...
- BZOJ 3555: [Ctsc2014]企鹅QQ hash
3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- Communications link failure报错的处理
一.报错的问题: 测试环境在做压力测试的时候爆出错误 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications l ...
- sharepoint 2013 未能加载类型"Microsoft.AnalysisServices.SharePoint.Integration.ReportGalleryView"
最近在做PowerPivot for sharepoint server 2013的时候,创建PowerPivot库,之后打开,出现了一个问题: 未能加载类型"Microsoft.Analy ...
- [Angular 2] Factory Provider
In this lesson, we discuss how and when to use factory providers, to enable dependencies that should ...
- [原创]如何写好SqlHelper 之终章
精简的美丽...... 标题有点大.但是,我觉得99%的接近了. 好了,下面我们来说说一个SqlHelper为了适应各种不同的业务需要,它应该具备哪些基本要素. 第一点.可控的事务. 事务是数据库操作 ...
- day02 Java基础
1.Java中的关键字都是小写的. 2.Java中的关键字 3.Java中的注释分为:单行注释.多行注释.文档注释 文档注释将被javadoc工具解析生成一个说明书. 4.Java中的常量分为字面值常 ...
- org.apache.hadoop.filecache-*
我不知道为什么这个包为什么是空的,从名字上看应该是一些管理文件缓存的类吗? 网上也没查到什么,各种群里也没大牛回答. 期望某位大牛能告诉我答案,谢谢