简体   繁体   English

NSArray到NSMutableArray

[英]NSArray to NSMutableArray

I am trying to pass an NSArray to a NSMutableArray but am having a few issues doing so and was hoping someone could help. 我正在尝试将NSArray传递给NSMutableArray,但这样做有一些问题,希望有人可以提供帮助。

- (void)CachedData:(NSArray *)gArray indexPath:(NSIndexPath *)gIndex dataSetToParse:(NSString *)string
{
    //Set dataSetToParse so the parsing delegates if statment works correctly
    dataSetToParse = string;

    //Calls method that sets the accessory tick
    [self setAccessoryIndexPath:gIndex];

    //Set array that can be used in this view
    [parsedDataArray addObjectsFromArray:gArray];


    //Use this method to pass NSData object to startTheParsingProcess method and also to initalize indexPathVariable
    [self startSortingTheArray:gArray];
}

When I try to log parsedDataArray after I addObjects to it all I get is 当我在向其添加对象之后尝试记录parsedDataArray时,我得到的只是

(null) (null) .... etc. (null)(null)....等

any help would be appreciated. 任何帮助,将不胜感激。

Update The main issue here is that I have 4 lots of arrays. 更新这里的主要问题是我有4个数组。 with 3 views, a main view sub view and then a sub subview. 具有3个视图,分别是主视图子视图和子视图。 each array has a refrence ID to the next array, I want to parse each array before I display them to check if there are any values in them based off the restriction string. 每个数组都有一个指向下一个数组的引用ID,我想在显示每个数组之前先解析每个数组,以检查其中是否有任何基于限制字符串的值。 If there are no values then I will either send the user back to the main view or just not allow them to select the cell that has an array with no related values. 如果没有值,那么我要么将用户发送回主视图,要么就是不允许他们选择具有不相关值的数组的单元格。 (I hope you get what I am doing here) (我希望你能明白我在这里所做的事情)

The solution I have come up with for that is to parsed the values in the parent view of where I intend to display them... 为此,我想出的解决方案是在要显示它们的父视图中解析这些值。

if you look at my views 如果你看我的看法

view 1
- view 2
-- view 3

I need a parsing delegate for view 1 and 2, because I need to check the values of view 3 in view 2.. However this is causing me an issue because I am using the same array to avid redundancy to return the value to the main view and create/check the values of the subview. 我需要一个用于视图1和2的解析委托,因为我需要在视图2中检查视图3的值。但是,这引起了我一个问题,因为我正在使用同一数组进行冗余备份以将值返回给主对象。查看并创建/检查子视图的值。

So I am trying to skip over the parser delegates of view 2 if i am not going to display anything in view 3, by passing my already parsed array into the mutablearray I will pass the data back with inside didselectcell method... 因此,如果我不打算在视图3中显示任何内容,那么我将尝试跳过视图2的解析器委托,通过将已经解析的数组传递给mutablearray,我将在didselectcell方法内部将数据传递回去...

Anyway I hope this makes sense.. its the only way I think I can do this.. if you know better please let me know your strategy. 无论如何,我希望这是有道理的。这是我认为可以做到的唯一方法。

Assuming the parsedDataArray is a mutable array declared somewhere else, this wouldn't make sense: 假设parsedDataArray是在其他地方声明的可变数组,则没有意义:

//Set array that can be used in this view
[parsedDataArray addObjectsFromArray:parsedDataArray];

Unless you mean to double all of the objects in the parsedDataArray. 除非您打算将parsedDataArray中的所有对象加倍。 I think what you meant is: 我认为您的意思是:

//Set array that can be used in this view
[parsedDataArray addObjectsFromArray:gArray];

But I can't be sure without more context or explanation. 但是我不能确定没有更多的上下文或解释。

NSArray *array = [NSArray arrayWithObjects:@"Raja",@"Ram",nil];

NSMutableArray *muArray = [NSMutableArray arrayWithArray:array];

check if garray is containing the data or not, by printing it in nslog 通过在nslog中打印来检查garray是否包含数据

also check if u have intialized parsedDataArray as below or not parsedDataArray=[[NSMutableArray alloc]init]; 还检查您是否已按如下所示初始化parsedDataArray或parsedDataArray = [[NSMutableArray alloc] init]; in Viewdidload delegate 在Viewdidload委托中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM