开源中国社区iOS客户端学习-(2)侧拉栏和设置界面

上一篇中提到

self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuViewController"];

其中leftMenuViewController即为侧拉栏的storyboard ID,在storyboard中找到这个tableViewController,可以发现它的class是SideMenuViewController。
再用一次上一篇中的图
这里写图片描述
可以在viewDidLoad进行一些设置,让界面更加美观

 self.tableView.backgroundColor = [UIColor titleBarColor];//设置背景颜色
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//tableView无分割线
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];//除去多余行

侧拉栏使用表视图构建,可以分成两个部分。
1)section的header用来创建“点击头像登录”

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 160;//设置高度
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    ......  
    return headerView;
}

2)为普通的tableViewCell,放置具体的选项。先看一下“设置”选项。

case 3: {
            SettingsPage *settingPage = [SettingsPage new];
            [self setContentViewController:settingPage];

            break;
        }

通过调用setContentViewController:转到设置界面

- (void)setcontentViewController:(UIViewController *)viewController{
    viewController.hidesBottomBarWhenPushed = YES;//跳转时隐藏TabBarController的BottomBar
    UINavigationController *nav = (UINavigationController *)((UITabBarController *)self.sideMenuViewController.contentViewController).selectedViewController;//将nav设置为已选的contentViewController
    [nav pushViewController:viewController animated:NO];

    [self.sideMenuViewController hideMenuViewController];//隐藏侧拉栏
}

不登陆时,设置界面共有五个选项。点击“清除缓存”选项只会弹出警告框,并没有真正作用(说不对的话,请不要打我),点击“给应用评分”选项跳转到App Store。

if (section == 0) {
        if (row == 0) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"确定要清除缓存的图片和文件?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alertView show];

        } else if (row == 1){

        }
    } else if (section == 1) {
        if (row == 0) {
            [self.navigationController pushViewController:[FeedbackPage new] animated:YES];
        } else if (row == 1) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/kai-yuan-zhong-guo/id524298520?mt=8"]];//点击“给应用评分”选项跳转到App Store
        } else if (row == 2) {
            [self.navigationController pushViewController:[AboutPage new] animated:YES];
        } else if (row == 3) {
            [self.navigationController pushViewController:[OSLicensePage new] animated:YES];
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值