Iphone 将NSMutablearray复制到另一个

Iphone 将NSMutablearray复制到另一个,iphone,copy,nsmutablearray,nsarray,Iphone,Copy,Nsmutablearray,Nsarray,我正在尝试将NSMutableArray复制到另一个,但它在UITableView上没有显示任何内容: NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two"]; NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil]; NSMutableArray *list = [[

我正在尝试将
NSMutableArray
复制到另一个,但它在
UITableView
上没有显示任何内容:

NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two"];

NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil];

NSMutableArray *list = [[NSMutableArray alloc] init];

[self.list addObjectsFromArray:myArray];
什么也没出现!怎么了

它使我的应用程序崩溃,因为我的
NSMutableArray中没有nil
如何将nil添加到它
addobject:nil
不起作用它会使应用程序崩溃:

static NSString * DisclosureButtonCellIdentifier = 
@"DisclosureButtonCellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: 
                         DisclosureButtonCellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                   reuseIdentifier: DisclosureButtonCellIdentifier]
            autorelease];
}
NSUInteger row = [indexPath row];

NSString *rowString =nil;

rowString = [list objectAtIndex:row];


cell.textLabel.text = rowString;

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[rowString release];
return cell;

由于参数列表中没有nil终止符,您对alloc-an-NSMutableArray的初始调用很可能会崩溃

此外,还有一个局部变量list和一个属性list。确保你正在实例化你认为你是什么。您可能需要执行以下操作:

NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two", nil];

NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil];

self.list = [[NSMutableArray alloc] init];

[self.list addObjectsFromArray:myArray];

问题可能是第4行中的
列表的本地声明与属性冲突。

存在一些问题。。。一个问题是您正在使用“initWithObjects”并添加上一个数组。这似乎是不必要的行为,因为您很可能希望将字符串@“1”和@“2”添加到数组中。您很可能打算使用
initWithArray
addObjectsFromArray
。(按照您所做的方式,将NSMutableArray(而不是其对象)添加到列表中)

第二个问题是,当使用initWithObjects时,需要列出每个对象,然后使用nil值终止列表。()换句话说,你需要使用

NSMutableArray *objectsToAdd = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", nil];
这可能会帮助您:

NSMutableArray *result  = [NSMutableArray arrayWithArray:array];


为什么要展示一些东西?发布您的CellForRowatingIndexPath:method的codeUpdate如何使用addObject将nil添加到NSMutableArray?它在cellForRowAtIndexPathNSMutableArray*myArray=[[NSMutableArray alloc]initWithArray:objectsToAdd]上使我的应用程序崩溃;initWithObjects需要单个对象,而不是可变数组。此外,myArray是不可变的。
NSMutableArray *result = [array mutableCopy]; //recommended