Screenshot of code that how to move to different screens through segue identifier。IOS中的左菜单栏
我从GitHub上的现有项目导入了一些文件,并在项目中创建了一个左侧菜单栏:主页,关于我们和登录。
当用户使用“登录”菜单栏项登录时,我想将“登录”项的标题更改为“注销”。用户应保持登录状态,直到用户按下“注销”。当用户注销时,该项目的标题应该变回“登录”。
注意:左侧菜单栏中的项目是静态单元格。
Screenshot of code that how to move to different screens through segue identifier。IOS中的左菜单栏
我从GitHub上的现有项目导入了一些文件,并在项目中创建了一个左侧菜单栏:主页,关于我们和登录。
当用户使用“登录”菜单栏项登录时,我想将“登录”项的标题更改为“注销”。用户应保持登录状态,直到用户按下“注销”。当用户注销时,该项目的标题应该变回“登录”。
注意:左侧菜单栏中的项目是静态单元格。
保存您的登录信息status(flag)
在NSUSerDefaults
。当你登录时,然后保存yes否则不。在你的cellForRowAtIndexPath
中通过检查该标志来相应地设置标题。并相应地管理操作(登录或注销过程)!
请你详细说明,我很新,我不明白。 @Lion – omer
目标C
1)首先保存你在indexPath登录状态如下
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"isLoggedIn"];
2)在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];
}
试试这个:https://github.com/mikefrederick/MFSideMenu – KKRocks
当你登录成功,然后设置登录成功布尔值userdefault和检查如果bool值为true,则使用[“”,“”,“注销”],如果为false,则使用[“”,“”,“登录”] –
请详细说明。 @Bhupat Bheda – omer