ios - 为多个用户创建相同的应用程序

标签 ios iphone storyboard xcode5

我已经为一个用户(/角色类型)开发了一个应用程序,现在希望为同一应用程序添加更多角色。因此,现在,不同的角色将根据分配的角色显示/隐藏某些功能。显然,我将拥有相同的登录页面来进入单个应用程序,这是检查角色的起点。这样做可以节省应用程序的屏幕数量。如何有效地实现这一目标?

任何显示多个角色登录的设计想法也将被接受。

最佳答案

我想你可以创建一个代表你不同角色的位掩码枚举

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/

相关文章:

ios - viewForAnnotation 详细披露更改当前位置以及引脚

ios - 在 iOS 文档目录中保留数据

objective-c - 使用 Storyboard时重用 UIViewController 实例

iphone - 从 iPhone 应用程序在 iCloud 上创建文件夹

wpf - 如何在 wpf 中为 Storyboard 设置参数?

ios - UITableView 页脚、 Storyboard和 Xcode 6 的自动布局问题

iphone - 在作为父级的父级的 View Controller 中调用方法

iphone - UITabBarItem 标题被 UIViewController 标题覆盖了吗?

ios 8 swift 如何使用 Storyboard设计多层

ios - 在纵向和横向模式下为 iPad 设置不同的约束