lost.in.code lost.in.code - 15 days ago 5
Objective-C Question

Moved view items in left menu SWRevealViewController objective c

I use SWRevealViewController in my project on objective c. Sometimes when I slide left menu, then first item is moved. Only first item, I don't know why because it has the same margins like others.

Also, it's not tableview, it's just static views which created in storyboard.

Sometimes it's showed incorrect This

enter image description here

It's need to be like That

enter image description here
First item moved sometimes.

Any ideas? Thx for help ;)

Answer

Please use table view it will easy for you with optimize code. You can navigate each view in didSelect method of tableView. Here is the code please try this.

arrMenuItems = [[NSMutableArray alloc]initWithObjects:@"HOME",@"YOUR WORK", @"BOOKMARKS", @"GETSTARTED",@"SETTING", @"LOG OUT",nil];


#pragma mark - Table view delegate and data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return arrMenuItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellid = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    cell.textLabel.text = [arrMenuItems objectAtIndex:indexPath.row];
    return cell;
}

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

    switch (indexPath.row) {
        case 0:{

           HomeViewController *rootViewController = InstantiateVC(@"HomeViewController");

                UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
                [navController setViewControllers: @[rootViewController] animated: YES];

                [self.revealViewController setFrontViewController:navController];
                [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
            }
            break;
        }

        case 1:{
            YourWorkViewController *homeVC = InstantiateVC(@"YourWorkViewController");

            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homeVC];
            [navController setViewControllers: @[homeVC] animated: YES];

            [self.revealViewController setFrontViewController:navController];
            [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];

            break;
        }

        case 2:{
            BookMarkViewController *writeToUsVC = InstantiateVC(@"BKBWriteToUsVC");

            writeToUsVC.isFromVCTag = WRITE_TO_US;

            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:writeToUsVC];
            [navController setViewControllers: @[writeToUsVC] animated: YES];

            [self.revealViewController setFrontViewController:navController];
            [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
            break;
        }
        case 3:{
            GetStartedViewController *aboutUsVC = InstantiateVC(@"BKBAboutVC");


            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:aboutUsVC];
            [navController setViewControllers: @[aboutUsVC] animated: YES];

            [self.revealViewController setFrontViewController:navController];
            [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
            break;
        }
        case 4:{
            SettingViewController *writeToUsVC = InstantiateVC(@"BKBWriteToUsVC");

            writeToUsVC.isFromVCTag = CONTACT_US;

            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:writeToUsVC];
            [navController setViewControllers: @[writeToUsVC] animated: YES];

            [self.revealViewController setFrontViewController:navController];
            [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
            break;
        }
        case 5:{
             LogOutViewController *writeToUsVC = InstantiateVC(@"BKBWriteToUsVC");

            writeToUsVC.isFromVCTag = CONTACT_US;

            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:writeToUsVC];
            [navController setViewControllers: @[writeToUsVC] animated: YES];

            [self.revealViewController setFrontViewController:navController];
            [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];



            break;
        }

        default:
            break;
    }

}

Please change your ViewController according your requirements.