问题1:应用启动时默认选择第一项
假设您正在使用SASlideMenu
问题中提到的代码。在您的ExampleMenuViewController
课程中,您需要添加以下内容,
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
if (indexPath) {
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
_ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _ __ _ __ _ __ _ _ __ _ __ _
问题2:默认选择第一项并设置主屏幕applicationWillEnterForeground
ExampleMenuViewController.h
在您的文件中添加以下方法声明,
@interface ExampleMenuViewController :SASlideMenuViewController<SASlideMenuDataSource>
- (void)selectFirstRowAndSetHomePage;
@end
ExampleMenuViewController.m
在您的文件中添加以下方法,
- (void)selectFirstRowAndSetHomePage {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
if (indexPath) {
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
NSString *identifier= [self.slideMenuDataSource initialSegueId];
if (identifier) {
[self performSegueWithIdentifier:identifier sender:self];
}
}
SASlideMenuAppDelegate.h
在您的课程中实施以下内容,
#import "ExampleMenuViewController.h"
和,
- (void)applicationWillEnterForeground:(UIApplication *)application {
ExampleMenuViewController *exampleMenuViewController = (ExampleMenuViewController *)self.window.rootViewController;
[exampleMenuViewController selectFirstRowAndSetHomePage];
}
那应该有帮助。
_ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _ __ _ __ _ __ _ _ __ _ __ _