为多个用户创建相同的应用程序
我开发了一个用户(/角色类型)的应用程序,现在希望为同一个应用程序添加更多角色。所以现在,不同的角色将显示/隐藏某些功能,具体取决于分配的角色。显然,我将有相同的登录页面进入单个应用程序,这是检查角色的起点。这样做可以节省我的应用程序的屏幕数量。如何有效实现这一点?为多个用户创建相同的应用程序
任何设计思想,以显示多个角色登录也将被接受。
我想你可以创建一个位掩码枚举代表你的型动物角色
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
}
谢谢你的宝贵答复。我希望你能稍微详细了解一下它的实现细节。 – user2741735 2015-02-12 17:41:41
@ user2741735我添加了更多细节 – KIDdAe 2015-02-13 08:37:19
我不明白这个问题。你遇到了什么问题? – lascort 2015-02-11 16:59:39
我没有问题,我只需要一个适当的方法来达到上述要求。主要根据角色显示/隐藏功能。我想通过使用标志,但它不会是一个有效的解决方案,我猜... – user2741735 2015-02-12 16:57:01