iphone - 将 NSMutablearray 复制到另一个

标签 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];

没有任何显示!怎么了?

它使我的应用程序崩溃,因为我的 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;

最佳答案

您最初调用分配 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];

关于iphone - 将 NSMutablearray 复制到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2057135/

相关文章:

ios - 在ios7中用日期对NSMutableArray进行排序

iphone - NSMutableArray insertObject 在随机索引

iphone - 由于内存泄漏导致应用程序崩溃

iphone - UIGraphicsBeginImageContext 导致内存(泄漏)溢出

iphone - 在 iPhone 应用程序中重新加载表格 View ?

python - Pandas:在数据帧之间复制一些值

c++ - 我不知道为什么c++中复制构造函数的调用不稳定

iphone - 如何将ical添加到iPhone应用程序

java - 将列表复制到另一个列表(带或不带 'new')之间的区别 - JAVA

ios - 更新可变数组