Reputation: 3015
I am following some tutorials. Now I am trying to develop an e-book. I downloaded this EPUB Reader library https://github.com/79144876/EpubPDFReader .as i have worked on latest XCODE so in every app i used storyboards not xib. In this library xibs are used. I am having difficulties to customise the library according to my requirements. What the library is doing is when app starts displays the table view with four rows 1.PDF 2.EPUB etc and on the clicking of following rows book will display. what i want to do is instead of showing the table view i want to show directly EpubViewController in the start. hope you understand the question. i am posting some code here
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [userDefaults objectForKey:@"AppleLanguages"];
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
RootViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSError *error;
NSString *phrase = nil;
switch (indexPath.row) {
//TXT
case 0:{
//text
}
break;
//PDF
case 1:{
}
break;
//EPUB
case 2:{
epubView = [[EPubViewController alloc] init];
[epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"The Chessmen of Mars" ofType:@"epub"]]];
epubView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:epubView animated:YES];
[epubView release];
}
break;
I don't want to load the controller when case 2 condition full files. I want to load this controller when application starts. Hope you get the point
images
Upvotes: 2
Views: 13738
Reputation: 8924
From iOS 13 onwards...
window
property is not available in AppDelegate.
You need to work with SceneDelegate
.
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
//Here I'm setting LoginViewController as my root view controller
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let rootVC = storyboard?.instantiateViewController(identifier: "LoginViewController") as? LoginViewController else {
print("ViewController not found")
return
}
let nav = UINavigationController(rootViewController: rootVC)
window?.rootViewController = nav
window?.makeKeyAndVisible()
}
}
Upvotes: 1
Reputation: 5666
In .h of AppDelegate file create Property
@property (nonatomic,retain) UINavigationController *navigationController;
@property (nonatomic, strong) EpubViewController *epubcontroller;
In .m AppDelegate file write below code in didFinishLaunchingWithOptions
epubcontroller=[[EpubViewController alloc] initWithNibName:@"EpubViewController" bundle:nil];
navigationController=[[UINavigationController alloc] initWithRootViewController:epubcontroller];
self.window.rootViewController = self.navigationController;
Upvotes: 0
Reputation: 144
in didFinishLaunchingWithOptions method of your appDelegate.m file write
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Make sure you create ViewController class of UIViewController type with xib.
Upvotes: 0
Reputation: 1380
In AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [userDefaults objectForKey:@"AppleLanguages"];
EPubViewController *epubView = [[EPubViewController alloc] init];
[epubView loadEpub:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"The Chessmen of Mars" ofType:@"epub"]]];
self.navigationController = [UINavigationController alloc]initWithRootViewController:epubView];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Upvotes: 0