应用程序在模拟器上运行,但不在iphone中的设备上运行

时间:2013-12-27 11:43:06

标签: iphone objective-c cocoa-touch

我正在使用SlideView Controller,主要是当应用程序通过dropbox进入(使用dropbox登录)时,它转到FirstViewController并且在Simulator中整个应用程序正常工作,但在设备进入FirstViewController时它甚至崩溃它显示了它的界面。

FirstViewController中,它与slideViewController链接,而slideViewController具有tableview和slideview的属性,以便显示下一个控制器(slideViewController)..

我有一些slideViewController的代码。即使在FirstViewController中,应用程序也在viewdidload下,然后是slideViewController,但我已经尝试了很多但是在设备应用程序中崩溃了。

任何人都可以帮我解决这个问题吗

我在下面发布我的代码..

 #import "SlideViewController.h"
    #import <QuartzCore/QuartzCore.h>
    #import "CustomViewController.h"
    #import "ClassViewController.h"
    #import "AssignmentViewController.h"
    #import "SectionViewController.h"
    #import "SlideViewControllerTableCell.h"
    #import "LogoutCell.h"
    #import "MainViewController.h"
    #import <DropboxSDK/DropboxSDK.h>

    #define kSVCLeftAnchorX                 100.0f
    #define kSVCRightAnchorX                190.0f
    #define kSVCSwipeNavigationBarOnly      NO


    @interface SlideViewNavigationBar : UINavigationBar {
    @private

        id <SlideViewNavigationBarDelegate> _slideViewNavigationBarDelegate;

    }

    @property (nonatomic, assign) id <SlideViewNavigationBarDelegate> slideViewNavigationBarDelegate;

    @end

    @implementation SlideViewNavigationBar (CustomImage)
    - (void)drawRect:(CGRect)rect {
        UIImage *image = [UIImage imageNamed:@"class button1.png"];

        [image drawInRect:CGRectMake(0, 0, self.frame.size.width+10, self.frame.size.height+10)];


        UIImage *image1 = [UIImage imageNamed:@"skirrwhite.png"];

        [image1 drawInRect:CGRectMake(40, 10,80, 26)];


    }
    @end



    @implementation SlideViewNavigationBar

    @synthesize slideViewNavigationBarDelegate = _slideViewNavigationBarDelegate;


    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

        [super touchesBegan:touches withEvent:event];

        [self.slideViewNavigationBarDelegate slideViewNavigationBar:self touchesBegan:touches withEvent:event];

    }

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

        [super touchesMoved:touches withEvent:event];

        [self.slideViewNavigationBarDelegate slideViewNavigationBar:self touchesMoved:touches withEvent:event];

    }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

        [super touchesEnded:touches withEvent:event];

        [self.slideViewNavigationBarDelegate slideViewNavigationBar:self touchesEnded:touches withEvent:event];

    }

    @end



    @implementation SlideViewController

    @synthesize delegate = _delegate;
    @synthesize calert;
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:@"SlideViewController" bundle:nil];
        if (self) {

            _touchView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
            _touchView.exclusiveTouch = NO;

            _overlayView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 44.0f, 320.0f, 416.0f)];

            _slideNavigationControllerState = kSlideNavigationControllerStateNormal;

        }
        return self;
    }


    - (void)dealloc {

        [_touchView release];
        [_overlayView release];
        [_slideNavigationController release];

        [super dealloc];

    }

    #pragma mark - View Lifecycle

    - (void)viewDidLoad {



        if (![self.delegate respondsToSelector:@selector(configureSearchDatasourceWithString:)] || ![self.delegate respondsToSelector:@selector(searchDatasource)]) {
            _searchBar.hidden = YES;
            _tableView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 460.0f);
        }

        _slideNavigationController.view.layer.shadowColor = [[UIColor blackColor] CGColor];
        _slideNavigationController.view.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
        _slideNavigationController.view.layer.shadowRadius = 4.0f;
        _slideNavigationController.view.layer.shadowOpacity = 0.75f;
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_slideNavigationController.view.bounds cornerRadius:4.0];
        _slideNavigationController.view.layer.shadowPath = path.CGPath;

        [(SlideViewNavigationBar *)_slideNavigationController.navigationBar setSlideViewNavigationBarDelegate:self];

        UIImage *searchBarBackground = [UIImage imageNamed:@"search_bar_background"];
        [_searchBar setBackgroundImage:[searchBarBackground stretchableImageWithLeftCapWidth:0 topCapHeight:0]];

        UIViewController *initalViewController = [self.delegate initialViewController];
        [self configureViewController:initalViewController];

        [_slideNavigationController setViewControllers:[NSArray arrayWithObject:initalViewController] animated:NO];

        [self addChildViewController:_slideNavigationController];

        [self.view addSubview:_slideNavigationController.view];

        if ([self.delegate respondsToSelector:@selector(initialSelectedIndexPath)])
            [_tableView selectRowAtIndexPath:[self.delegate initialSelectedIndexPath] animated:NO scrollPosition:UITableViewScrollPositionTop];

    }

    #pragma mark Instance Methods

    - (void)configureViewController:(UIViewController *)viewController {

          UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
       [tempButton setFrame:CGRectMake(1, 1, 14, 30)]; // your Home Button Image width and height.
        [tempButton addTarget:self action:@selector(menuBarButtonItemPressed:) forControlEvents:UIControlEventTouchUpInside];
        [tempButton setImage:[UIImage imageNamed:@"ic_drawer.png"] forState:UIControlStateNormal];
        //[tempButton setImage:[UIImage imageNamed:@"twitterIcon.png"] forState:UIControlStateHighlighted];
        [viewController.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:tempButton]];

    }

    - (void)menuBarButtonItemPressed:(id)sender {

        if (_slideNavigationControllerState == kSlideNavigationControllerStatePeeking) {

            [self slideInSlideNavigationControllerView];
            return;

        }

        UIViewController *currentViewController = [[_slideNavigationController viewControllers] objectAtIndex:0];

        if ([currentViewController conformsToProtocol:@protocol(SlideViewControllerSlideDelegate)] && [currentViewController respondsToSelector:@selector(shouldSlideOut)]) {


            if ([(id <SlideViewControllerSlideDelegate>)currentViewController shouldSlideOut]) {

                [self slideOutSlideNavigationControllerView];

            }


        } else {

            [self slideOutSlideNavigationControllerView];

        }

    }

    - (void)slideOutSlideNavigationControllerView {

        _slideNavigationControllerState = kSlideNavigationControllerStatePeeking;

        [UIView animateWithDuration:0.2 delay:0.0f options:UIViewAnimationOptionCurveEaseInOut  | UIViewAnimationOptionBeginFromCurrentState animations:^{

            _slideNavigationController.view.transform = CGAffineTransformMakeTranslation(260.0f, 0.0f);

        } completion:^(BOOL finished) {

            [_slideNavigationController.view addSubview:_overlayView];

        }];

    }

    - (void)slideInSlideNavigationControllerView {

        [UIView animateWithDuration:0.2 delay:0.0f options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState animations:^{

            _slideNavigationController.view.transform = CGAffineTransformIdentity;

        } completion:^(BOOL finished) {

            [self cancelSearching];

            _slideNavigationControllerState = kSlideNavigationControllerStateNormal;
            [_overlayView removeFromSuperview];

        }];

    }





    - (void)slideSlideNavigationControllerViewOffScreen {

        _slideNavigationControllerState = kSlideNavigationControllerStateSearching;

        [UIView animateWithDuration:0.2 delay:0.0f options:UIViewAnimationOptionCurveEaseInOut  | UIViewAnimationOptionBeginFromCurrentState animations:^{

            _slideNavigationController.view.transform = CGAffineTransformMakeTranslation(320.0f, 480.0f);

        } completion:^(BOOL finished) {

            [_slideNavigationController.view addSubview:_overlayView];

        }];

    }

    #pragma mark UITouch Logic


    - (void)cancelSearching {

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching) {
            [_searchBar resignFirstResponder];
            _slideNavigationControllerState = kSlideNavigationControllerStateNormal;
            _searchBar.text = @"";
            [_tableView reloadData];
        }

    }

    #pragma mark SlideViewNavigationBarDelegate Methods

    - (void)slideViewNavigationBar:(SlideViewNavigationBar *)navigationBar touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

        [self touchesBegan:touches withEvent:event];

    }

    - (void)slideViewNavigationBar:(SlideViewNavigationBar *)navigationBar touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

        [self touchesMoved:touches withEvent:event];

    }

    - (void)slideViewNavigationBar:(SlideViewNavigationBar *)navigationBar touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

        [self touchesEnded:touches withEvent:event];

    }

    #pragma mark UINavigationControlerDelgate Methods 

    - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

        [self cancelSearching];

        if ([[navigationController viewControllers] count] > 1) {

            _slideNavigationControllerState = kSlideNavigationControllerStateDrilledDown;

        } else {

            _slideNavigationControllerState = kSlideNavigationControllerStateNormal;

        }

    }

    #pragma mark UITableViewDelegate / UITableViewDatasource Methods

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching) {
            return [[self.delegate searchDatasource] count];
       } else {
            return [[[[self.delegate datasource] objectAtIndex:section] objectForKey:kSlideViewControllerSectionViewControllersKey] count];        
        }
    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching) {
            return 1;
        } else {
            return [[self.delegate datasource] count];
        }
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        static NSString *resuseIdentifier = @"SlideViewControllerTableCell";
        SlideViewControllerTableCell *cell = [tableView dequeueReusableCellWithIdentifier:resuseIdentifier];

        if (!cell) {

            cell = [[[SlideViewControllerTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resuseIdentifier] autorelease];

        }



        NSDictionary *viewControllerDictionary = nil;

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching) {
            viewControllerDictionary = [[self.delegate searchDatasource] objectAtIndex:indexPath.row];
        } else {
            viewControllerDictionary = [[[[self.delegate datasource] objectAtIndex:indexPath.section] objectForKey:kSlideViewControllerSectionViewControllersKey] objectAtIndex:indexPath.row];
        }

        cell.textLabel.text = [viewControllerDictionary objectForKey:kSlideViewControllerViewControllerTitleKey];

        if ([[viewControllerDictionary objectForKey:kSlideViewControllerViewControllerIconKey] isKindOfClass:[UIImage class]]) {
            cell.imageView.image = [viewControllerDictionary objectForKey:kSlideViewControllerViewControllerIconKey];
            //cell.imageView.image =[[]]
        } else {
            cell.imageView.image = nil;
        }
        UIView *v = [[[UIView alloc] init] autorelease];
        v.backgroundColor = [UIColor redColor];
        [cell setBackgroundColor:[UIColor clearColor]];
        cell.textLabel.textColor = [UIColor colorWithRed:190.0f/255.0f green:197.0f/255.0f blue:212.0f/255.0f alpha:1.0f];
        cell.textLabel.textColor = [UIColor colorWithRed:190.0f/255.0f green:197.0f/255.0f blue:212.0f/255.0f alpha:1.0f];
        //cell.textLabel.highlightedTextColor = self.textLabel.textColor;
        cell.textLabel.shadowColor = [UIColor colorWithRed:33.0f/255.0f green:38.0f/255.0f blue:49.0f/255.0f alpha:1.0f];
        cell.textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0f];

        cell.imageView.clipsToBounds = YES;
        cell.imageView.contentMode = UIViewContentModeScaleAspectFit;


        NSString *strTemp = [NSString stringWithFormat:@"%@",[viewControllerDictionary objectForKey:kSlideViewControllerViewControllerTitleKey]];

    //    float height = [strTemp boundingRectWithSize:(CGSize)13.0 options:nil attributes:nil context:nil];
        float height = [strTemp sizeWithFont:[UIFont fontWithName:@"Helvetica" size:13.0] constrainedToSize:CGSizeMake(300, 30) lineBreakMode:NSLineBreakByWordWrapping].height;
        [cell.textLabel setNumberOfLines:0];
        [cell.textLabel setText:strTemp];
        [cell.textLabel setFrame:CGRectMake(0, 0, 160, height)];






        return cell;
    }

    -(IBAction)logout:(id)sender
    {
        [[DBSession sharedSession] unlinkAll];
        MainViewController *fc = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];

        [self.navigationController pushViewController:fc animated:YES];
        [fc release];

    }



    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching)
            return nil;

        NSDictionary *sectionDictionary = [[self.delegate datasource] objectAtIndex:section];

        if ([sectionDictionary objectForKey:kSlideViewControllerSectionTitleKey]) {

            NSString *sectionTitle = [sectionDictionary objectForKey:kSlideViewControllerSectionTitleKey];

            if ([sectionTitle isEqualToString:kSlideViewControllerSectionTitleNoTitle]) {

                return nil;

            } else {

                return sectionTitle;

            }

        } else {

            return nil;

        }

    }

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching)
            return nil;

        NSString *titleString = [self tableView:tableView titleForHeaderInSection:section];

        if (!titleString)
            return nil;

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 22.0f)];
        imageView.image = [[UIImage imageNamed:@"section_background"] stretchableImageWithLeftCapWidth:0.0f topCapHeight:0.0f];

        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectInset(imageView.frame, 10.0f, 0.0f)];
        titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
        titleLabel.textAlignment = UITextAlignmentLeft;
        titleLabel.textColor = [UIColor colorWithRed:125.0f/255.0f green:129.0f/255.0f blue:146.0f/255.0f alpha:1.0f];
        titleLabel.shadowColor = [UIColor colorWithRed:40.0f/255.0f green:45.0f/255.0f blue:57.0f/255.0f alpha:1.0f];
        titleLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
        titleLabel.backgroundColor = [UIColor clearColor];
        titleLabel.text = titleString;
        [imageView addSubview:titleLabel];
        [titleLabel release];

        return [imageView autorelease];

    }


    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching) {
            return 0.0f;
        }
        else if ([self tableView:tableView titleForHeaderInSection:section]) {
            return 22.0f;
        } else {
            return 0.0f;
        }
    }

    -(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
    {
        if (section == 4) {
            return 40.0;
        }
        else {
            return 10.0;
        }
    }



    -(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
    {

        if(section == 4)
        {



           UIButton *logoutImage = [UIButton buttonWithType:UIButtonTypeCustom];
            [logoutImage setFrame:CGRectMake(35, 15, 150, 100)];
            [logoutImage setImage:[UIImage imageNamed:@"logoutbutton.PNG"] forState:UIControlStateNormal];
            [logoutImage addTarget:self action:@selector(logout:) forControlEvents:UIControlEventTouchUpInside];

        return [logoutImage autorelease];
        }
        else
        {
            return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        }

       //return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

    }


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"indexPath ==%d",indexPath.section);
        NSDictionary *viewControllerDictionary = nil;

        if (_slideNavigationControllerState == kSlideNavigationControllerStateSearching) {
            viewControllerDictionary = [[self.delegate searchDatasource] objectAtIndex:indexPath.row];
        } else {
            viewControllerDictionary = [[[[self.delegate datasource] objectAtIndex:indexPath.section] objectForKey:kSlideViewControllerSectionViewControllersKey] objectAtIndex:indexPath.row];
        }

        Class viewControllerClass = [viewControllerDictionary objectForKey:kSlideViewControllerViewControllerClassKey];
        NSString *nibNameOrNil = [viewControllerDictionary objectForKey:kSlideViewControllerViewControllerNibNameKey];
        UIViewController *viewController = [[viewControllerClass alloc] initWithNibName:nibNameOrNil bundle:nil];

        if ([self.delegate respondsToSelector:@selector(configureViewController:userInfo:)])
            [self.delegate configureViewController:viewController userInfo:[viewControllerDictionary objectForKey:kSlideViewControllerViewControllerUserInfoKey]];

        [self configureViewController:viewController];

        [_slideNavigationController setViewControllers:[NSArray arrayWithObject:viewController] animated:NO];
        [viewController release];

        [self slideInSlideNavigationControllerView ];


        if(indexPath.section == 4)
        {
            if (indexPath.row == 0){



                [[DBSession sharedSession] unlinkAll];
                MainViewController *fc = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];

                [self.navigationController pushViewController:fc animated:YES];
                [fc release];
            }
        }

    }







    #pragma mark UISearchBarDelegate Methods

    - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {

        if ([self.delegate respondsToSelector:@selector(configureSearchDatasourceWithString:)]) {

            [self slideSlideNavigationControllerViewOffScreen];

            [self.delegate configureSearchDatasourceWithString:searchBar.text];

            [_tableView reloadData];

        }

    }

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

        if ([self.delegate respondsToSelector:@selector(configureSearchDatasourceWithString:)]) {

            [self.delegate configureSearchDatasourceWithString:searchBar.text];

            [_tableView reloadData];

        }

    }

    - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {

        [self cancelSearching];

        [self slideOutSlideNavigationControllerView];

        [_tableView reloadData];

    }

    @end

ind the log says that:
2013-12-27 18:12:04.989 Skirr[1534:a0b] Application windows are expected to have a root view controller at the end of application launch
2013-12-27 18:12:45.918 Skirr[1534:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x032745e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x021b88b6 objc_exception_throw + 44
    2   CoreFoundation                      0x03228316 -[__NSPlaceholderArray initWithObjects:count:] + 390
    3   CoreFoundation                      0x0324bce9 +[NSArray arrayWithObject:] + 73
    4   Skirr                               0x0000943d -[SlideViewController viewDidLoad] + 1597
    5   UIKit                               0x00e2d318 -[UIViewController loadViewIfRequired] + 696
    6   UIKit                               0x00e2d5b4 -[UIViewController view] + 35
    7   UIKit                               0x00e473e2 -[UINavigationController _startCustomTransition:] + 778
    8   UIKit                               0x00e540c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
    9   UIKit                               0x00e54cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
    10  UIKit                               0x00f8e181 -[UILayoutContainerView layoutSubviews] + 213
    11  UIKit                               0x00d84267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    12  libobjc.A.dylib                     0x021ca81f -[NSObject performSelector:withObject:] + 70
    13  QuartzCore                          0x005622ea -[CALayer layoutSublayers] + 148
    14  QuartzCore                          0x005560d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    15  QuartzCore                          0x00555f40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    16  QuartzCore                          0x004bdae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    17  QuartzCore                          0x004bee71 _ZN2CA11Transaction6commitEv + 393
    18  QuartzCore                          0x004bf544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    19  CoreFoundation                      0x0323c4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    20  CoreFoundation                      0x0323c41f __CFRunLoopDoObservers + 399
    21  CoreFoundation                      0x0321a344 __CFRunLoopRun + 1076
    22  CoreFoundation                      0x03219ac3 CFRunLoopRunSpecific + 467
    23  CoreFoundation                      0x032198db CFRunLoopRunInMode + 123
    24  GraphicsServices                    0x034ce9e2 GSEventRunModal + 192
    25  GraphicsServices                    0x034ce809 GSEventRun + 104
    26  UIKit                               0x00d19d3b UIApplicationMain + 1225
    27  Skirr                               0x000056a2 main + 130
    28  libdyld.dylib                       0x06896725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
    }

提前致谢

1 个答案:

答案 0 :(得分:0)

解释错误消息:

类中发生错误:Skirr方法:-[SlideViewController viewDidLoad],错误是添加了一个nil对象。

查看该方法并找到将某些内容添加到数组中的位置。