惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
S
Securelist
V
Vulnerabilities – Threatpost
C
Cyber Attacks, Cyber Crime and Cyber Security
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
Hacker News - Newest:
Hacker News - Newest: "LLM"
P
Palo Alto Networks Blog
T
Troy Hunt's Blog
SecWiki News
SecWiki News
Security Archives - TechRepublic
Security Archives - TechRepublic
T
The Blog of Author Tim Ferriss
Project Zero
Project Zero
Microsoft Security Blog
Microsoft Security Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
F
Full Disclosure
阮一峰的网络日志
阮一峰的网络日志
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Attack and Defense Labs
Attack and Defense Labs
Know Your Adversary
Know Your Adversary
WordPress大学
WordPress大学
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
The Last Watchdog
The Last Watchdog
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
H
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
云风的 BLOG
云风的 BLOG
月光博客
月光博客
T
The Exploit Database - CXSecurity.com
I
InfoQ
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
U
Unit 42
腾讯CDC
小众软件
小众软件
V2EX - 技术
V2EX - 技术
罗磊的独立博客
Cloudbric
Cloudbric
Recorded Future
Recorded Future
IT之家
IT之家
Google DeepMind News
Google DeepMind News
C
CXSECURITY Database RSS Feed - CXSecurity.com

博客园 - 黎波

精至手机药典Windows Phone 7版 [WP7]修改 Pivot 控件的 PivotItem 标题字体大小 [WP7]CheckBox 文字自动换行 Windows Phone 7 系统主题颜色RGB和Hex值 [WP7]MD5加密字符串 [iOS]MD5加密字符串 [WP7]关于 ListBox 的 SelectionChanged 事件 [Android]MD5加密字符串 [Android]获取设备IP地址 精至手机药典iPhone版 [iOS]NSString常用代码 目标身高iPhone版 目标身高Android版 [iOS]让Xcode 4.2生成的app支持老的iOS设备(armv6) [iOS]升级到 Xcode 4.1 后 sqlite3.h 引起 Expected declaration specifiers before 'interface' 错误 [转载]用手机玩转汽车 体验安吉星手机应用程序 [iOS]Xcode 4.1 bug: Text Field 引起 EXC_BAD_ACCESS 错误的解决 精至手机药典Android版 [Android]使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法
如何检查对象的类型[iOS/Android/Windows Phone]
黎波 · 2012-03-14 · via 博客园 - 黎波

iOS

使用 NSObject 基类的 isKindOfClass: 方法。

声明:

- (BOOL)isKindOfClass:(Class)aClass
描述:
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class. (required)

参数:

aClass: A class object representing the Objective-C class to be tested.

返回值:

YES if the receiver is an instance of aClass or an instance of any class that inherits from aClass, otherwise NO.

示例代码:

for (UIView *ctrl in [self childViewControllers]) {
    if ([ctrl isKindOfClass:[UITextField class]]) {
        [(UITextField*)ctrl setText:@""];
    }
    else if ([ctrl isKindOfClass:[UISwitch class]]) {
        [(UISwitch*)ctrl setOn:NO];
    }
}

Android

The instanceof operator compares an object to a specified type. You can use it to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface.

示例代码:

void checkforTextView(View v)
{
    if(v instanceof TextView)
    {
        // This is a TextView control
    } else {
        // This is not a TextView control
    }
}

Windows Phone

C# 的 is 操作符关键字。Checks if an object is compatible with a given type. An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown.

示例代码:

foreach (UIElement ctrl in this.ContentPanel.Children) {
    if (ctrl is TextBlock) {
        //TextBlock
    }
    else if (ctrl is TextBox) {
        //TextBox
    }
}

作者:黎波
博客:http://bobli.cnblogs.com/
日期:2012年3月14日