IOS左侧菜单栏上的图像

时间:2017-11-11 12:36:29

标签: ios objective-c

我有一个左侧菜单栏,我正在使用表视图控制器在其中添加项目。我想在左侧菜单栏的项目列表顶部添加一个图像,如屏幕截图所示。如何将其添加到我的左侧菜单栏?我的左侧菜单表视图的控制器是这个,

    - (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

    NSUserDefaults *successDefaults = [NSUserDefaults standardUserDefaults];
    NSString *str111=[NSString stringWithFormat:@"%@",[successDefaults valueForKey:@"currentUser"]];

    currentLoginStatus = [str111 intValue];
    if(currentLoginStatus == 1){
        LeftMenuDataImages1=[[NSArray alloc]initWithObjects:@"pec.png",@"hecc.png",@"ssec.png",@"aec.png",@"lec.png",@"cec.png",@"wec.png",@"tec.png" ,@"sec.png",@"cRoom.png",@"hellp.png",@"vec.png",@"ceta.png",nil];
            }

    else if(currentLoginStatus == 2){
        LeftMenuDataImages1=[[NSArray alloc]initWithObjects:@"pec.png",@"hecc.png",@"ssec.png",@"aec.png",@"lec.png",@"cec.png",@"wec.png",@"tec.png" ,@"sec.png",@"cRoom.png",@"hellp.png",@"",@"",nil];
    }


    else{
         LeftMenuDataImages1=[[NSArray alloc]initWithObjects:@"",@"hecc.png",@"ssec.png",@"aec.png",@"lec.png",@"cec.png",@"wec.png",@"tec.png" ,@"sec.png",@"cRoom.png",@"hellp.png",@"",@"",nil];
    }
}

    -(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];

    NSUserDefaults *successDefaults = [NSUserDefaults standardUserDefaults];
    NSString *success= [successDefaults valueForKey:@"Success"];

    if ([success isEqual:@"Success"]){
        string1 = [successDefaults stringForKey:@"name"];
    }

    NSString *str111=[NSString stringWithFormat:@"%@",[successDefaults valueForKey:@"currentUser"]];

    currentLoginStatus = [str111 intValue];
    if(currentLoginStatus == 1) {
         LeftMenuData1=[[NSArray alloc]initWithObjects:string1,@"Home",@"Show Franchiser",@"AboutUs",@"Logout",@"Contact Us",@"Wanted",@"Terms&Conditions",@"Share App",@"Live Support",@"Help & Guide",@"View Your Properties",@"Chat", nil];
        [self.tableView reloadData];

    }
    else if(currentLoginStatus == 2){
        LeftMenuData1=[[NSArray alloc]initWithObjects:string1,@"Home",@"Show Franchiser",@"AboutUs",@"Logout",@"Contact Us",@"Wanted",@"Terms&Conditions",@"Share App",@"Live Support",@"Help & Guide",@"View Your Properties",@"", nil];
        [self.tableView reloadData];

    }

    else{

        LeftMenuData1=[[NSArray alloc]initWithObjects:@"",@"Home",@"Show Franchiser",@"AboutUs",@"Login/Register",@"Contact Us",@"Wanted",@"Terms&Conditions",@"Share App",@"Live Support",@"Help & Guide",@"",@"",nil];
        [self.tableView reloadData];

    }

}

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [LeftMenuData1 count];
}

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];


    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];

    }
    cell.textLabel.text=[LeftMenuData1 objectAtIndex:indexPath.row];
    cell.imageView.image=[UIImage imageNamed:[LeftMenuDataImages1 objectAtIndex:indexPath.row]];


    return cell;
}

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    float height = 40;

    NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];
    NSString *str111=[NSString stringWithFormat:@"%@",[successDefaults valueForKey:@"currentUser"]];
     currentLoginStatus = [str111 intValue];
    if(currentLoginStatus == 0 && indexPath.row == 0)
        height = 0;

    return height;
}

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

    UITableViewCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath];
    NSLog(@"%@",selectedCell.textLabel.text);

    AppDelegate *app=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];
    NSInteger row = indexPath.row;
    NSString *str=[NSString stringWithFormat:@"%@",[LeftMenuData1 objectAtIndex:indexPath.row]];
    NSLog(@"%@",str);
    if (row == 0) {

        NSString *str111=[NSString stringWithFormat:@"%@",[successDefaults valueForKey:@"currentUser"]];

         currentLoginStatus = [str111 intValue];
        if(currentLoginStatus == 1)
        {

            UpViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"Up"];
            UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];

            [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];

        } else if(currentLoginStatus == 2)
        {
            UserProfileViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"profile"];
            UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];

            [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
        }
    }else if(row == 1){

        HomePageViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];

        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];

    }else if (row == 2){

        FransFormViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"frans"];

        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];



        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];



    }else if (row == 3){
        AboutUsViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"AboutUs"];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];

    }else if (row == 4){

        NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];

        if ([[successDefaults valueForKey:@"Success"] isEqualToString:@"Success"]) {
            [successDefaults setObject:@"NO" forKey:@"Success"];
            [successDefaults setObject:@"0" forKey:@"currentUser"];

            [successDefaults synchronize];
            [successDefaults synchronize];
            [app.drawer toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];

        }else{
            GeneralLoginViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"General"];
            UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
            [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];

        }

    }else if(row == 5){
        ContactInfoViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactInfo"];

        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];

        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
    }else if (row == 6){
        WantedViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"WantedViewController"];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
    }else if (row == 7){

        Terms_ConditionViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"Terms"];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
    }else if (row == 8){

        ShareViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"Share"];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];

    }else if (row == 9){

        ZendeskChat *chat=[[ZendeskChat alloc]init];
        [chat viewDidLoadchat];

    }


    else if (row == 10){

        HelpandGuide *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"help"];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];

    }

    else if (row == 11){

        NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];

        if ([[successDefaults valueForKey:@"Success"] isEqualToString:@"Success"]){

        ViewPersonalTableViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewProps"];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
        [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];

        }


    }else{

    }

    if (row == 12){

        [[FIRAuth auth]
         signInAnonymouslyWithCompletion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
             if (error == nil) {
                 NSLog(@"User UID is %@",user.uid);
             }

         }];

        NSUserDefaults *successDefaults = [NSUserDefaults standardUserDefaults];
        NSString *str111=[NSString stringWithFormat:@"%@",[successDefaults valueForKey:@"currentUser"]];

        currentLoginStatus = [str111 intValue];
       if(currentLoginStatus == 1){

            ChatViewViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"cheta"];
            UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
            [app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
           NSLog(@"HHH");
        }

    }else if(currentLoginStatus == 2){

    }else{

    }

}

我想添加这样的图片, image below

0 个答案:

没有答案