将NSMutablearray复制到另一个

ste*_*osn 5 iphone copy nsmutablearray nsarray

我正在尝试复制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];
Run Code Online (Sandbox Code Playgroud)

什么都没有出现!怎么了?

它崩溃了我的应用程序,因为我没有对我的nil NSMutableArray如何添加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;
Run Code Online (Sandbox Code Playgroud)

Ben*_*ieb 19

您初始调用分配NSMutableArray很可能会崩溃,因为您的参数列表中没有nil终止符.

此外,您还有一个局部变量,列表和属性列表.确保你实例化你的想法.您可能需要这样做:

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

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

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

[self.list addObjectsFromArray:myArray];
Run Code Online (Sandbox Code Playgroud)