ios - 比较类给出了不正确的输出

标签 ios objective-c compare

我正在使用下面的代码来检查 View Controller 。

NSLog(@"addProductClicked 1===%@", self.class);

NSLog(@"addProductClicked 2===%@", [CategoriesViewController class]);

if ([self.class isKindOfClass:[CategoriesViewController class]]) {

    NSLog(@"you go it right");

} else {
    NSLog(@"you go it wrong");
}

我得到的输出如下。

addProductClicked 1===CategoriesViewController
addProductClicked 2===CategoriesViewController

you go it wrong

知道出了什么问题吗?


更新一下,下面是我定义的 View Controller ...

@interface CategoriesViewController : GlobalViewController {

现在在 GlobalViewController 中,我有方法在上面检查...

最佳答案

要进行类检查的变量应作为对象而不是类传入。

if ([self isKindOfClass:[CategoriesViewController class]]) {
    NSLog(@"you go it right");
} else {
    NSLog(@"you go it wrong");
}

关于ios - 比较类给出了不正确的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32987501/

相关文章:

ios - UISearchDisplayController 奇怪的行为(视频)

ios - Swift - 通过分段控件更改 ImageView 背景图像

iphone - 在 Interface Builder 中连接 iOS socket

ios - 如何从 NSDate iOS 获取 UTC 时间

ios - 在 UICollectionViewCell 中隐藏 UIImage

将 C 中的日期与(使用 time.h 库)进行比较

windows - 使用 powershell 比较两个列表并查找列表一中的名称而不是列表二中的名称

ios - 制作重叠 View

mysql - SQL查询: Alter columny value if columnx value is greater,小于或等于

ios - 无法在欧洲访问 Firebase 数据库,而在亚洲可以在 iOS 应用程序中访问