我已经为一个用户(/角色类型)开发了一个应用程序,现在希望为同一应用程序添加更多角色。因此,现在,不同的角色将根据分配的角色显示/隐藏某些功能。显然,我将拥有相同的登录页面来进入单个应用程序,这是检查角色的起点。这样做可以节省应用程序的屏幕数量。如何有效地实现这一目标?
任何显示多个角色登录的设计想法也将被接受。
最佳答案
我想你可以创建一个代表你不同角色的位掩码枚举
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
}
关于ios - 为多个用户创建相同的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28459913/