我为一个用户(/角色类型)开发了一个应用程序,现在希望为同一个应用程序添加更多角色。现在,不同的角色将显示/隐藏某些功能,具体取决于分配的角色。显然,我将在单个应用程序中输入相同的登录页面,这是检查角色的起点。这样做会保存我的应用程序的屏幕数。如何有效地实现这一目标?
任何显示登录多个角色的设计构思也将被接受。
答案 0 :(得分: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分配给您的用户
然后将它存放在某个地方(可能是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
}