【问题标题】:How to interpret document.state == 12 (iCloud)如何解释 document.state == 12 (iCloud)
【发布时间】:2011-11-08 08:45:47
【问题描述】:

每当我从 iCloud 加载 UIDocument 时,我都会像这样检查它的状态:

NSLog(@"Library loadFromContents: state = %d", self.documentState);

在某些情况下,我收到了导致崩溃的 documentState 8 或 12。我现在想知道 8 和 12 到底代表什么。据我所知, documentState 是一个位字段,因此它有许多不同的标志。 docs 透露:

enum {
UIDocumentStateNormal          = 0,
UIDocumentStateClosed          = 1 << 0,
UIDocumentStateInConflict      = 1 << 1,
UIDocumentStateSavingError     = 1 << 2,
UIDocumentStateEditingDisabled = 1 << 3   }; 
typedef NSInteger UIDocumentState;

但是,我不知道如何在我的情况下解释这一点。如何找出 8 和 12 代表什么?

【问题讨论】:

    标签: iphone objective-c ios5 icloud uidocument


    【解决方案1】:

    在枚举内部,他们做了一些位移。他们也可以这样写:

    enum {
    UIDocumentStateNormal          = 0,
    UIDocumentStateClosed          = 1,
    UIDocumentStateInConflict      = 2,
    UIDocumentStateSavingError     = 4,
    UIDocumentStateEditingDisabled = 8   }; 
    typedef NSInteger UIDocumentState;
    

    向左移位基本上是移位运算符后给出的任何数字的 2 次方... 1

    状态 8 表示 UIDocumentStateEditingDisabled 和 12 表示 UIDocumentStateEditingDisabledUIDocumentStateSavingError

    【讨论】:

    • 非常感谢您提供如此清晰的解释!
    【解决方案2】:

    处理这些通知的建议方法是检查if(state == UIDocumentStateInConflict),而是使用这样的逻辑AND:

    if (state & UIDocumentStateInConflict) {
        // do something...
    }
    

    参见官方文档中的"An Example: Letting the User Pick the Version" in "Document-based app programming guide"

    【讨论】:

      猜你喜欢
      • 2018-12-08
      • 2011-07-20
      • 2012-02-14
      • 2015-03-23
      • 2021-05-08
      • 2013-09-13
      • 2020-02-07
      • 2015-07-03
      • 1970-01-01
      相关资源
      最近更新 更多