【问题标题】:Left Menu Bar in IOSIOS左侧菜单栏
【发布时间】:2017-05-26 04:28:38
【问题描述】:

Screenshot of code that how to move to different screens through segue identifier.

我从 GitHub 上的现有项目中导入了一些文件,并制作了一个左侧菜单栏,其中包含以下项目:主页、关于我们和登录。

当用户使用“登录”菜单栏项登录时,我希望“登录”项的标题更改为“注销”。用户应保持登录状态,直到用户按下“注销”。当用户注销时,项目的标题应该变回“登录”。

注意:左侧菜单栏中的项目是静态单元格。

【问题讨论】:

  • 当你登录成功然后在 userdefault 中设置登录成功的 bool 值并检查 bool 值是否为 true 然后使用 ["","","logout"],如果为 false 则使用 ["", "","登录"]
  • 你能详细说明一下吗? @Bhupat Bheda
  • @omer 可以给你看代码,我可以修改它们
  • 重新格式化并修复了一些语法以阐明 OP 的要求

标签: ios objective-c xcode


【解决方案1】:

将您的登录信息status(flag) 保存在NSUSerDefaults 中。当您登录时,请保存 yes else no。在您的cellForRowAtIndexPath 中,通过检查该标志相应地设置标题。并相应地管理操作(登录或注销过程)!

【讨论】:

  • 你能详细说明一下吗?我很新,我不明白。 @狮子
【解决方案2】:

目标-C

1) 首先保存你的登录状态如下

[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"isLoggedIn"];

2) 在 indexPath 的 cellForRow 中写下这段代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (indexPath.row == YOUR TABLE CELL) {
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isLoggedIn"]) {
         cell.lblMenuTitle.text = @"Log out";
        } else {
         cell.lblMenuTitle.text = @"Log In";
       }
     }
      [return cell];
    }

3) 在tableView的DidSelect方法中写下这段代码

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

            if (indexPath.row == YOUR TABLE CELL) {
                if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isLoggedIn"]) {
                     [[NSUserDefaults standardUserDefaults] setBool:false forKey:@"isLoggedIn"];
                } else {
                     [[NSUserDefaults standardUserDefaults] setBool:true forKey:@"isLoggedIn"];
                }
                [tableView reloadData];
            }
        }

4) 最后在左侧菜单类的 viewWillAppear 中添加代码

 -(void)viewWillAppear:(BOOL)animated
 {
   [tableView reloadData];
 }

【讨论】:

  • 我没有使用 nsuserdefault 即时获取响应并解析它。在替换 nsuserdefault 时要写什么? @Jaydeep
  • 是的,但是当您获得登录响应时,请对其进行解析并将“isLoggedIn”之类的标志存储到 NSUserDefaults 中,然后在您调用注销服务时从 NSUserDefaults 中删除该值。所以它将作为状态标志工作,指示用户是否登录?以及您可以在 cellForRow 方法中使用相同的标志来管理登录和注销操作。
  • 不好意思看不懂可以详细解释。 @Jaydeep
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-27
  • 2015-02-04
  • 2014-06-23
  • 1970-01-01
相关资源
最近更新 更多