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

推荐订阅源

Project Zero
Project Zero
F
Fortinet All Blogs
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
S
Schneier on Security
N
News and Events Feed by Topic
N
News | PayPal Newsroom
H
Help Net Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
The Exploit Database - CXSecurity.com
Attack and Defense Labs
Attack and Defense Labs
博客园 - Franky
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
A
About on SuperTechFans
AWS News Blog
AWS News Blog
S
Secure Thoughts
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
Recorded Future
Recorded Future
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
Help Net Security
Help Net Security
人人都是产品经理
人人都是产品经理
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
大猫的无限游戏
大猫的无限游戏
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
H
Hacker News: Front Page
P
Proofpoint News Feed
N
News and Events Feed by Topic
H
Heimdal Security Blog
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
L
LangChain Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - 黎波

精至手机药典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日