如何将对象从类传递到 anthoer? - 从一个班级到另一个班级的看法?
我想传递一个在第一个视图中创建的视图,就像这里的
if (self.bookDetailViewController == nil)
{
iPhoneStreamingPlayerViewController *aBookDetail = [[iPhoneStreamingPlayerViewController alloc] initWithNibName:@"iPhoneStreamingPlayerView" bundle:nil];
self.bookDetailViewController = aBookDetail;
NSLog(@"View initilaized");
[aBookDetail release];
}
//call a method from another class like over here
[booksNavController1 nowPlayingView:bookDetailViewController];
//in 2nd view controller
-(void)nowPlayingView:(iPhoneStreamingPlayerViewController *)NPView
{
nowPlayingSong = NPView;
}
-(void)getSng:(NSString *)sng
{
name = sng;
}
//ibacton for toolbar button
-(IBAction)nowPlaying
{
Music_appAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.booksNavController pushViewController:nowPlayingSong animated:YES];
}
nsloged 的内容“应用程序试图在目标上推送一个 nil 视图控制器。 响应 SpringBoard 的终止而终止。”
I want to pass a view which has been made in 1st view like over here
if (self.bookDetailViewController == nil)
{
iPhoneStreamingPlayerViewController *aBookDetail = [[iPhoneStreamingPlayerViewController alloc] initWithNibName:@"iPhoneStreamingPlayerView" bundle:nil];
self.bookDetailViewController = aBookDetail;
NSLog(@"View initilaized");
[aBookDetail release];
}
//call a method from another class like over here
[booksNavController1 nowPlayingView:bookDetailViewController];
//in 2nd view controller
-(void)nowPlayingView:(iPhoneStreamingPlayerViewController *)NPView
{
nowPlayingSong = NPView;
}
-(void)getSng:(NSString *)sng
{
name = sng;
}
//ibacton for toolbar button
-(IBAction)nowPlaying
{
Music_appAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.booksNavController pushViewController:nowPlayingSong animated:YES];
}
here is what is nsloged "Application tried to push a nil view controller on target .
Terminating in response to SpringBoard's termination."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要释放 BookDetail。即注释掉这一行:
尝试一下,看看它是否有效。
Don't release aBookDetail. i.e. comment out this line:
Try that and see if it works.
你必须以不同的方式构建你的程序。得到 null 的原因是因为您的类在打印输出之前执行。
抱歉,您必须以不同的方式构建您的课程。
或者,您可以使用
(AppDelegate *)[[UIApplication sharedApplication]delegate];
允许在类和 AppDelegate 之间共享,然后相应地子类化。You have to structure your programm differnetly. The reason why you get null is because your class executes before you print the output.
Sorry but you have to structure your class differently.
Or you could use the
(AppDelegate *)[[UIApplication sharedApplication]delegate];
to allow sharing between the class and the AppDelegate and then subclass accordingly.