2015-02-11 57 views
0

我開發了一個用戶(/角色類型)的應用程序,現在希望爲同一個應用程序添加更多角色。所以現在,不同的角色將顯示/隱藏某些功能,具體取決於分配的角色。顯然,我將有相同的登錄頁面進入單個應用程序,這是檢查角色的起點。這樣做可以節省我的應用程序的屏幕數量。如何有效實現這一點?爲多個用戶創建相同的應用程序

任何設計思想,以顯示多個角色登錄也將被接受。

+2

我不明白這個問題。你遇到了什麼問題? – lascort 2015-02-11 16:59:39

+0

我沒有問題,我只需要一個適當的方法來達到上述要求。主要根據角色顯示/隱藏功能。我想通過使用標誌,但它不會是一個有效的解決方案,我猜... – user2741735 2015-02-12 16:57:01

回答

1

我想你可以創建一個位掩碼枚舉代表你的型動物角色

typedef enum : NSUInteger { 
    RoleType1 = (1 << 0), // = 001 
    RoleType2 = (1 << 1), // = 010 
    RoleType3 = (1 << 2) // = 100 
} RoleType; 

使用位掩碼讓你多角色分配給您的用戶

對於爲例,你可以這樣做:

RoleType myRoles = RoleType1|RoleType2 // here myRoles = 011 

將RoleType1和RoleType2分配給用戶

Th恩股票這個地方(的AppDelegate @property也許?)

@property (nonatomic) RoleType myRoles; 

((AppDelegate*)[[UIApplication sharedApplication] delegate]).myRoles = RoleType1|RoleType2 

然後你只需要測試並您的用戶有什麼樣的角色,以顯示在屏幕或菜單項,等等一些內容......

// We get the current roles 
RoleType myRoles = ((AppDelegate*)[[UIApplication sharedApplication] delegate]).myRoles 
if (myRoles & RoleType1) { // This is the way to test if myRoles and RoleType1 have a common bit 
    // Then user has role1, then we want to show a button for example 
    button.hidden = NO; 
} else { 
    // User does not have role1 
    button.hidden = YES 
} 
+0

謝謝你的寶貴答覆。我希望你能稍微詳細瞭解一下它的實現細節。 – user2741735 2015-02-12 17:41:41

+0

@ user2741735我添加了更多細節 – KIDdAe 2015-02-13 08:37:19

相關問題