Resolved Blank Black Screen

Discussion in 'iOS Programming' started by Bayan, Jul 10, 2012.

  1. Bayan, Jul 10, 2012
    Last edited: Jul 17, 2012

    Bayan macrumors newbie

    Joined:
    Apr 13, 2012
    #1
    When I run my app and press the button that takes me to the page Jaw, a blank black screen is displayed instead. I don't get any kind of run error or anything in my log. When I added an NSLog to the ViewDidLoad to check if the method is evoked, nothing is displayed in my log! Does anyone know what is causing this?

    This is the code of the page "Jaw",
    .h:
    Code:
    #import <UIKit/UIKit.h>
    #import <sqlite3.h>
    #import "ViewController.h"
    #import "NewCase.h"
    #import "Info.h"
    #import "Needed.h"
    #import "Available.h"
    #import "import.h"
    #import "Result.h"
    #import "Ps.h"
    #import "Patiant.h"
    
    @interface Jaws : UIViewController <UINavigationControllerDelegate>
    {
        sqlite3 *database;
        NSString *file;
    }
    @property (retain, nonatomic) NSString *file;
    @property (strong, nonatomic) IBOutlet UIView *view;
    @property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
    @property (weak, nonatomic) IBOutlet UILabel *UpperT;
    @property (weak, nonatomic) IBOutlet UIImageView *Upper;
    @property (weak, nonatomic) IBOutlet UILabel *LowerT;
    @property (weak, nonatomic) IBOutlet UIImageView *Lower;
    @property (weak, nonatomic) IBOutlet UIBarButtonItem *Back;
    - (IBAction)Back:(id)sender;
    -(void)retrieve;
    @end
    .m
    Code:
    #import "Jaws.h"
    
    @interface Jaws ()
    
    @end
    
    @implementation Jaws
    @synthesize Upper, Lower, file, scrollView, Back, UpperT, LowerT, view;
    NewCase *new;
    
    -(BOOL) respondsToSelector:(SEL)aSelector {
        printf("SELECTOR: %s\n", [NSStringFromSelector(aSelector) UTF8String]);
        return [super respondsToSelector:aSelector];
    }
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self)
        {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self retrieve];
        
        [scrollView setContentSize:CGSizeMake(340, 1000)];
        // Do any additional setup after loading the view from its nib.
    }
    
    - (void)viewDidUnload
    {
        [self setScrollView:nil];
        [self setBack:nil];
        [self setUpper:nil];
        [self setLower:nil];
        [self setUpperT:nil];
        [self setLowerT:nil];
        [self setView:nil];
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    -(void)retrieve
    {
        int type;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"TTSData.sql"];
        
        if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) 
        {
            NSString *presql = [ NSString stringWithFormat:@"SELECT * FROM Jaw WHERE file = '%d' ", [file intValue]];
            const char *sql = [presql UTF8String];
            sqlite3_stmt *searchStatement;
            
            if (sqlite3_prepare_v2(database, sql, -1, &searchStatement, NULL) == SQLITE_OK) 
            {
                while (sqlite3_step(searchStatement) == SQLITE_ROW) 
                {
                    UIImage *jaw = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 0)]];
                    
                    type = sqlite3_column_int(searchStatement, 2);
                    Upper.image= jaw;
                    
                    if ([new.JType isEqualToString:@"0"])
                    {
                        LowerT.text = @"NO Lower Jaw";
                    }
                    
                    else if ([new.JType isEqualToString:@"1"])
                    {
                        UpperT.text = @"Lower Jaw";
                        LowerT.text = @"NO Upper Jaw";
                    }
                    
                    else
                    {
                        Upper.image= jaw;
                        Lower.image= jaw;
                    }
                }
            }
        }
    }
    
    - (IBAction)Back:(id)sender
    {
        Patiant *a = [[Patiant alloc] initWithNibName:nil bundle:nil]; 
        a.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentModalViewController:a animated:YES];
    }
    @end
    
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Where's the code that actually presents the Jaws view controller?
     
  3. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #3
    This is it:
    Code:
    Jaws *i = [[Jaws alloc] initWithNibName:nil bundle:nil]; 
        i.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:i animated:YES];
    
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    That's not what he's looking for.

    He wants the code of the method that is called when the button that summons the Jaws view is called.
     
  5. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #5
    Yes, what I've posted is what's inside the method.
    Code:
    - (IBAction)Info:(id)sender
    {
        Jaws *i = [[Jaws alloc] initWithNibName:nil bundle:nil]; 
        i.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:i animated:YES];
    }
    There's also another method in another page that calls Jaws:
    Code:
    - (IBAction)ViewJaws:(id)sender
    {
        Jaws *i = [[Jaws alloc] initWithNibName:nil bundle:nil];
        i.file = file;
        i.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:i animated:YES];
    }
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Is i non-nil when this line is called?:
    Code:
    [self presentModalViewController:i animated:YES];
     
  7. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #7
    How can I make sure of that?

    I have the same code everywhere calling different view controllers and it works. such as,
    Code:
    - (IBAction)NewCase:(id)sender
    {
        NewCase *i = [[NewCase alloc] initWithNibName:nil bundle:nil]; 
        i.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:i animated:YES];
    }
    The Jaws code used to work before but I don't know what changed now, a black screen is displayed instead.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    A number of ways:

    1) check the value in code
    Code:
    if (i) { ... }
    2) set a breakpoint after assigning i and examine its value

    3) NSLog its value after assignment

    I'm sure there are others.
     
  9. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    I would set a breakpoint in your viewDidLoad then and step-through it. How far does it get?
     
  11. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #11
    Nothing happens and when I included an NSLog line inside the method, there is no output. So I'm guessing the ViewDidLoad was never reached.

    When I added breakpoints in the methods calling the view controllers, this is what I got:
    [​IMG]

    Someone told me to put the below method in all my .m that are causing the problem
    Code:
    -(BOOL) respondsToSelector:(SEL)aSelector {
        printf("SELECTOR: %s\n", [NSStringFromSelector(aSelector) UTF8String]);
        return [super respondsToSelector:aSelector];
    }
    when I added it to my Result.m and called the view controller, the following was output:
    Code:
    SELECTOR: _lastKnownInterfaceOrientation
    SELECTOR: _completionBlock
    SELECTOR: _didFinishPresentTransition
    when I called the Jaws view controller, the output was:
    Code:
    SELECTOR: _lastKnownInterfaceOrientation
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    How is the UI for Jaws setup? Do you have a NIB/XIB for it?
     
  13. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #13
    UIView. Yes, I have.
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    Did you create it at the same time as your Jaws class, using the "with XIB for user interface" option? If so, is it just black?

    EDIT:

    Another guess is that your retrieve method is holding up your main run-loop, therefore blocking your UI.
     
  15. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #15
    Yes and yes.

    I commented the whole method and it still displays a black screen!

    Thank you for your help dejo, I really appreciate every suggestion.
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    What I mean by this: is the UI for your Jaws XIB empty except for a black background?

    Although if you are calling presentModalViewController: and yet your viewDidLoad is not getting called that is a serious issue. One which I'm not entirely sure what could be causing that.
     
  17. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #17
    No, it's not empty. It has a tool bar, a tab bar, text labels and two images.
    I tried deleting them all where the view controller is just an empty UIView but the problem still remains.

    The problem is happening in two of my classes although they BOTH used to work before!
     
  18. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #18
    I don't suppose you are using any kind of source-control-management and can review/revert any changes that you may have done?

    What happens if you create a new Jaws-like viewController and use that instead? If that works, you may have to recreate Jaws.
     
  19. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #19
    You mean UNDO? if not, then no I don't know what source-control-management is.

    I already tried that before even crating this thread. I created a new .h .m .xib with a different name but same code as Jaws.h, Jaws.m and Jaws.xib. It produces the same problem.
     
  20. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #20
    git, svn, cvs, etc. So, probably not.

    Don't put in all the same code right away. Start with a only the most-basic code (i.e. that created by the File > New...) and change something simple but obvious, such as the background color for the view (red is usually pretty obvious!). Does that appear? Yes? Good. Add more pieces, bit-by-bit. No red view? Stop and diagnose the very simple code you've added.
     
  21. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #21
    I fixed it :)
    Turns out there was a UIView property that wasn't needed.

    Again, thanks for the help dejo.
     
  22. Icy1007 macrumors 6502a

    Icy1007

    Joined:
    Feb 26, 2011
    Location:
    Cleveland, OH
    #23
    What was the UIView property that wasn't needed? If you don't mind me asking.
     
  23. Bayan thread starter macrumors newbie

    Joined:
    Apr 13, 2012
    #24
    Sorry for my late reply, I don't remember very well now but I think it was an empty UIView that I have added on top of my original view.
     

Share This Page