将NSMutablearray复制到另一个 [英] Copy NSMutablearray to another
问题描述
I am trying to copy NSMutableArray
to another but it does not show me anything at the UITableView
:
NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two"];
NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil];
NSMutableArray *list = [[NSMutableArray alloc] init];
[self.list addObjectsFromArray:myArray];
没有出现!什么是错误?
Nothing show up! What is wrong?
它会崩溃我的应用程序,因为我没有nil在 NSMutableArray
如何添加nil到它? addobject:nil
不工作会导致应用程式崩溃:
It crashes my app because I do not have nil at my NSMutableArray
how can I add nil to it? addobject:nil
does not work it crashes the app:
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终止符。
Your initial call to alloc an NSMutableArray will most likely crash, since you don't have a nil terminator in your argument list.
此外,还有一个局部变量,列表和一个属性列表。确保你实例化你认为你是什么。您可能需要这样做:
Also, you have a local variable, list, and a property, list. Make sure you're instantiating what you think you are. You might need to do this:
NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two", nil];
NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil];
self.list = [[NSMutableArray alloc] init];
[self.list addObjectsFromArray:myArray];
这篇关于将NSMutablearray复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!