2

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

enter image description here enter image description here

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
hellosheikh
  • 2,929
  • 8
  • 49
  • 115
  • possible duplicate of [Set rootViewController of UINavigationController by method other than initWithRootViewController](http://stackoverflow.com/questions/16215034/set-rootviewcontroller-of-uinavigationcontroller-by-method-other-than-initwithro) – NANNAV Mar 15 '14 at 08:30

4 Answers4

1

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()
  }
}
Mahendra
  • 8,448
  • 3
  • 33
  • 56
0

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;
}
Venk
  • 5,949
  • 9
  • 41
  • 52
Surfer
  • 1,370
  • 3
  • 19
  • 34
0

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;
Indrajeet
  • 5,490
  • 2
  • 28
  • 43
  • thanks for your answer. only problem is it isn't displaying the naviagtion at the top. which was displaying earlier – hellosheikh Mar 15 '14 at 08:56
0

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.