PlaylistViewController

PlaylistViewController

本文介绍了将NSMutableArray传递给另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在两个视图控制器之间传递NSMutableArray。请让我知道我能为此做些什么

I am trying to pass a NSMutableArray between two view controller. Please let me know what can i do for this

在PlaylistViewController.h文件中我有

In the PlaylistViewController.h file I have

NSMutableArray *SongArray;
@property(nonatomic,retain)NSMutableArray *SongArray;

我希望传递给另一个视图控制器

which I wish to pass to another view controller

推荐答案

您可以通过两种方式分享:

You can share in two ways:


  1. 使用属性

示例

.h file

    @interface ABCController : UIViewController
    {
        NSMutableArray *detailArray;
    }
    @property(nonatomic,retain)NSMutableArray *detailArray;

.m 文件中

    XYZController *xyzVC = [[XYZController alloc] initWithNibName:@"XYZController" bundle:nil];
    xyzVC.detailArray = self.detailArray;

    [self.navigationController pushViewCsecondView:xyzVC animated:YES];


    **XYZController.h**

    @interface XYZController : UIViewController
    {
        NSMutableArray *detailArray;
    }

@property(nonatomic,retain)NSMutableArray *detailArray;




  1. 使用 NSUserDefaults

  1. Using NSUserDefaults

示例

     [[NSUserDefaults standardUserDefaults] setValue:SongArray forKey:@"songArray"];
     [[NSUserDefaults standardUserDefaults] synchronize];

     NSMutableArray *arr = [[NSUserDefaults standardUserDefaults] valueForKey:@"songArray"];

这篇关于将NSMutableArray传递给另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:38