2014-11-24 2 views
0

동일한 슬라이드 애니메이션이 서브 메뉴 인 this과 같은 메뉴가 있습니다. SecondMenu.xib라는 xib 파일 이름을 만듭니다. 파일 소유자는 UIViewController이며 SecondMenuController로 이름을 지정합니다. REFrosted (check the link) 프로젝트를 확인하면 DEMOMenuViewController (UIViewController)가 있습니다. 메서드 didSelectRowAtIndexPath :. 내 코드에서 변경했습니다.NSArrayM replaceObjectAtIndex : withObject : 객체는 'Nothing이 될 수 없습니다.'

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    NSMutableArray *controllers = [[NSMutableArray alloc] init]; 
    for (unsigned i = 0; i < 1; i++) { 
     [controllers addObject:[NSNull null]]; 
    } 
    self.viewControllers = controllers; 
    SecondMenuController *controller = [self.viewControllers objectAtIndex:0]; 

    if ((NSNull *)controller == [NSNull null]) { 
     controller = [[SecondMenuController alloc] initWithNibName:@"SecondMenu" bundle:nil]; 
     [self.viewControllers replaceObjectAtIndex:0 withObject:controller]; 

    } 

    controller.view.frame = CGRectMake(-self.view.frame.size.width, 0,self.view.frame.size.width,self.view.frame.size.height); 

    [self.view addSubview:controller.view]; 


    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
     controller.view.frame = CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height); 
    } completion:^(BOOL finished) { 
     NSLog(@"Done!"); 
    }]; 

    //[self hideMenu]; 

} 

하위 메뉴 (즉, SecondMenuController)에 연결할 때 해당 코드가 작동합니다. 내 SecondMenuController에서 버튼을 추가합니다 (이 버튼은 DEMOHomeViewController에 연결되며 스토리 보드 식별자는 homeController입니다). (나는 첫 번째 코드에서 위에서 언급 무엇을로) : 여기에 내가 didSelectRowAtIndexPath에 내 코드로 변경하기 전에 내가 REFrosted이 코드를 얻을 내 버튼

- (IBAction)buttonConnect:(id)sender { 
    DEMONavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentController"]; 

    DEMOHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"homeController"]; 
    navigationController.viewControllers = @[homeViewController]; 

    self.frostedViewController.contentViewController = navigationController; 
    [self.frostedViewController hideMenuViewController]; 
} 

의 코드입니다. 왜이 오류가 발생합니까?

'NSInvalidArgumentException', reason: '*** -[__NSArrayM replaceObjectAtIndex:withObject:]: object cannot be nil' 

모든 파일을 가져옵니다. 내가 이해 한대로, 파일 소유자에게 연결하는 파일을 가져올 때. 이것은 모든 메서드 나 함수를 제어 할 수 있다는 것을 의미합니다.이 메서드는 내 SecondMenuController에 인스턴스화 할 때 사용됩니다 (이 메서드는 경험이 풍부하고 틀린 경우 수정합니다. 시스템 작동 방법을 알고 싶습니다.). 내 코드를 참조하십시오. 내가 여기서 뭔가 못 찾았 니? 당신을 위해이 문제를 해결할 수있는 방법에 대한 조언을 듣고이 오류가 발생하는 이유를 설명합니다.

DEMONavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentController"]; 

    DEMOHomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"homeController"]; 
    navigationController.viewControllers = @[homeViewController]; 
+0

오류 메시지에 대해 이해하지 못하는 점은 무엇입니까? 그것은'controller'가 nil이라고 말합니다, 그것이 nil이 아니라고 확인 했습니까? NSLog() 예를 들어? 코드를 디버깅해야합니다. – zaph

+0

예 homeViewController는 nil입니다. 왜 그게 없습니까? 클래스는 이미 보드에 연결되어 있습니다. – user3818576

+0

디버깅 할 시간입니다. 신중하게 모든 것을 확인하고 오타, 클래스 이름 등을 다시 확인하십시오. 문서를 다시 읽으십시오. – zaph

답변

0

답변을 검색하는 데 2 ​​일 소요됩니다. 나는 그것을 마침내 얻는다.

SecondMenuController가 DEMOHomeViewController에 연결하지 않아 단추를 클릭 할 때 DEMOHomeViewController가 nil 인 이유는 SecondMenuController 클래스로 인스턴스화하더라도 마찬가지입니다. 나는 지금 배운다. 코드

첫 번째 코드는 다음과 같습니다. 나는 지금은 일하고 내 버튼

DEMONavigationController *navigationController = [self.myself instantiateViewControllerWithIdentifier:@"contentController"]; 

DEMOSecondViewController *secondViewController = [self.myself instantiateViewControllerWithIdentifier:@"homeController"]; 

navigationController.viewControllers = @[secondViewController]; 


self.ref.frostedViewController.contentViewController = navigationController; 
    [self.ref.frostedViewController hideMenuViewController]; 

에서

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil myStoryBoard:(UIStoryboard *) xStoryBoard ref: (id) xRef 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
     self.myself = xStoryBoard; 
     self.ref = xRef; 
    } 
    return self; 
} 

SecondMenuController.m

에서이 SecondMenuController.h

@property (nonatomic, weak) UIStoryboard * myself; 
@property (nonatomic, strong) REFrostedViewController * ref; 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil myStoryBoard:(UIStoryboard *) xStoryBoard ref: (id) xRef; 

를 추가합니다. initWithNibName : 메소드를 DEMOMenuViewController에 호출하기 만하면됩니다.

0

콘솔 로그는 NSArray에 nil 객체를 삽입하려고 시도했음을 의미하며 허용되지 않습니다. 어떤 이유로 든 빈 객체를 추가해야하는 경우 (NSArray *)[NSNull null]을 대신 사용하십시오.

+0

감사합니다 russell. 이미 확인 했어. 제가 놓칠 수있는 유일한 코드는 두 컨트롤러 사이에 연결을 추가하지 않았습니다. – user3818576

관련 문제