2011-03-30 101 views
0

我试图执行从我的FirstViewController我SecondViewController的方法,和它的作品,该方法被调用因为我看到我的消息(的NSLog(@“printSomething”))在日志控制台。 问题是,该方法试图移动UIToolBar,但它不。 如果我把从自己的viewController它的工作原理,在UIToolBar动作,但是当我把它从另一个的viewController ...执行方法的方法,但UIToolBar无可奈何动画工具栏

FirstViewController.m

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 
           initWithTitle:@"Opciones"            
             style:UIBarButtonItemStyleBordered 
             target:secondViewController 
             action:@selector(showOptions)]; 

SecondViewController.m

-(void)showOptions{ 
NSLog(@"printSomething"); 
[self.toolBar setFrame:CGRectMake(0, 40, 320, 50)]; 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:.35]; 
[self.toolBar setFrame:CGRectMake(0, 180, 320, 50)]; 
[self.toolBar setUserInteractionEnabled:YES]; 
[UIView commitAnimations]; 

}

感谢乌拉圭回合重播。

回答

0

更改您的NSLog语句来此:

NSLog(@"self.toolbar is 0x%x",self.toolBar); 

,看看值为非空。这是一个非常常见的问题 - 向Objective-C发送消息给空对象并不是运行时错误。

+0

它打印0x0,无论如何我应该怎么做才能使它工作? – 2011-03-30 17:52:30

+0

这意味着变量为空 - 它没有指向任何地方。您需要提供对第二个视图控制器的工具栏的有效引用。当您实例化第二个视图控制器时,您可以将它作为参数传递,然后执行self.toolbar = MyToolbarParameter。 – Rayfleck 2011-03-30 17:55:57