如何将对象从类传递到 anthoer? - 从一个班级到另一个班级的看法?

发布于 2024-11-14 05:11:21 字数 1072 浏览 1 评论 0原文

我想传递一个在第一个视图中创建的视图,就像这里的

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我心暖 2024-11-21 05:11:21

不要释放 BookDetail。即注释掉这一行:

    [aBookDetail release];

尝试一下,看看它是否有效。

Don't release aBookDetail. i.e. comment out this line:

    [aBookDetail release];

Try that and see if it works.

亢潮 2024-11-21 05:11:21

你必须以不同的方式构建你的程序。得到 null 的原因是因为您的类在打印输出之前执行。

Parser *parserClass = [Parser new];
parserClass.array = [[NSArray alloc]initWithObjects:@"One",@"Two", nil];
NSLog(@"%@", parserClass.array);

抱歉,您必须以不同的方式构建您的课程。

或者,您可以使用 (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.

Parser *parserClass = [Parser new];
parserClass.array = [[NSArray alloc]initWithObjects:@"One",@"Two", nil];
NSLog(@"%@", parserClass.array);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文