应用程序运行在模拟器上,但不是在iphone的设备上 [英] Application run on simulator but not on device in iphone

查看:179
本文介绍了应用程序运行在模拟器上,但不是在iphone的设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 SlideView Controller ,主要是当应用程序通过dropbox(使用dropbox登录)进入 FirstViewController 在模拟器整个应用程序是正常工作,但在设备,当它进入到FirstViewController它崩溃即使它显示其界面。



FirstViewController ,它与slideViewController和slideViewController链接有tableview和slideview的属性,所以下一个控制器(slideViewController)出现..



我有一些代码为slideViewController。甚至在FirstViewController中,应用程序在 viewdidload 下,然后slideViewController,但我尝试了很多但在设备应用程序崩溃。



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



我在下面发布我的代码。

  #importSlideViewController.h
#import< QuartzCore / QuartzCore.h>
#importCustomViewController.h
#importClassViewController.h
#importAssignmentViewController.h
#importSectionViewController.h
#import SlideViewControllerTableCell.h
#importLogoutCell.h
#importMainViewController.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 :事件];

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

}

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

[super touchesEnded:touches withEvent :事件];

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

}

@end



@implementation SlideViewController

@synthesize delegate = _代表;
@synthesize calert;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:@SlideViewControllerbundle: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 - 查看生命周期

- (void)viewDidLoad {



if(![self.delegate respondingToSelector:@selector(configureSearchDatasourceWithString :)] ||![self.delegate responsesToSelector:@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 respondingToSelector:@selector(initialSelectedIndexPath)])
[_tableView selectRowAtIndexPath:[self.delegate initialSelectedIndexPath] animated:NO scrollPosition:UITableViewScrollPositionTop];

}

#pragma mark实例方法

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

UIButton * tempButton = [UIButton buttonWithType:UIButtonTypeCustom];
[tempButton setFrame:CGRectMake(1,1,14,30)]; //您的主页按钮图片宽度和高度。
[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 responsesToSelector:@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);

}完成:^(BOOL完成){

[_slideNavigationController.view addSubview:_overlayView];

}];

}

- (void)slideInSlideNavigationControllerView {

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

_slideNavigationController.view.transform = CGAffineTransformIdentity;

}完成:^(BOOL完成){

[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);

}完成:^(BOOL完成){

[_slideNavigationController.view addSubview:_overlayView];

}];

}

#pragma mark UITouch Logic


- (void)cancelSearching {

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

}

#pragma mark SlideViewNavigationBarDelegate方法

- (void)slideViewNavigationBar:(SlideViewNavigationBar *)navigationBar touchesBegan: *)触发事件:(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方法

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

[self cancelSearching];

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

_slideNavigationControllerState = kSlideNavigationControllerStateDrilledDown;

} else {

_slideNavigationControllerState = kSlideNavigationControllerStateNormal;

}

}

#pragma mark UITableViewDelegate / UITableViewDatasource方法

- (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:@Helveticasize: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:@Helveticasize: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:@MainViewControllerbundle: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-Boldsize: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 ){
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 respondingToSelector:@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:@MainViewControllerbundle:nil];

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

}






$ b b #pragma mark UISearchBarDelegate方法

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

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

[self slideSlideNavigationControllerViewOffScreen];

[self.delegate configureSearchDatasourceWithString:searchBar.text];

[_tableView reloadData];

}

}

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

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

[self.delegate configureSearchDatasourceWithString:searchBar.text];

[_tableView reloadData];

}

}

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

[self cancelSearching] ;

[self slideOutSlideNavigationControllerView];

[_tableView reloadData];

}

@end

ind日志说:
2013-12-27 18:12:04.989 Skirr [1534 :a0b]应用程序窗口应该在应用程序启动结束时有一个根视图控制器
2013-12-27 18:12:45.918 Skirr [1534:a0b] ***由于未捕获异常而终止应用程序'NSInvalidArgumentException ',reason:'*** - [__ NSPlaceholderArray initWithObjects:count:]:尝试从对象插入nil对象[0]'
***第一次调用堆栈:

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:以NSException类型的未捕获异常结束
(lldb)
}
解决方案

解释错误消息:



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



看看这个方法,找到一个正在添加到数组的地方。


I am using SlideView Controller and mainly when application enter through dropbox(login with dropbox) it goes to FirstViewController and in Simulator whole app is working correctly but in device when it enter to FirstViewController it crash even it show its interface.

in FirstViewController,it linked with slideViewController and slideViewController have property of tableview and slideview so that next controller(slideViewController) is appear..

I have some code for slideViewController. Even in FirstViewController, application is goes under viewdidload and then slideViewController but i have tried lot of but in device application got crash.

Can anyone help me to get me out of this issue

i am posting my code below..

 #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) 
    }

Thanks in advance

解决方案

Interpreting the error message:

The error occurred in the class: Skirr method: -[SlideViewController viewDidLoad] and the error was adding a nil object.

Look at that method and find a place where something is being added to an array.

这篇关于应用程序运行在模拟器上,但不是在iphone的设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆