gpt4 book ai didi

ios - 在左侧菜单 SWRevealViewController objective c 中移动了 View 项

转载 作者:行者123 更新时间:2023-11-29 11:52:04 29 4
gpt4 key购买 nike

我在 objective-c 的项目中使用 SWRevealViewController。有时当我向左滑动菜单时,第一个项目被移动。只有第一项,我不知道为什么,因为它的边距与其他项相同。

此外,它不是 TableView ,它只是在 Storyboard 中创建的静态 View 。

有时会显示不正确的This

enter image description here

需要像那样

enter image description here第一项有时会移动。

有什么想法吗?感谢您的帮助;)

最佳答案

请使用 TableView ,优化代码对您来说很容易。您可以在 tableView 的 didSelect 方法中导航每个 View 。这是代码,请试试看。

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;
}

}

请根据您的要求更改您的 ViewController。

关于ios - 在左侧菜单 SWRevealViewController objective c 中移动了 View 项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40719484/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com