我正在尝试将 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/