Copy NSMutablearray to another

I am trying to copy NSMutableArrayto another, but it does not show me anything in UITableView:

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

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

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

[self.list addObjectsFromArray:myArray];

I can not see anything! What's wrong?

This is crashing my application because I don't have nil on mine NSMutableArray, how can I add nil to it? addobject:nildoes not work, this leads to a crash of the application:

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;
+5
source share
4 answers

Your initial call to distribute NSMutableArray is most likely a failure, since you do not have a null terminator in the argument list.

In addition, you have a local variable, a list, and a list of properties. Make sure you create what you consider yourself. You may 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];
+19

:

NSMutableArray *result  = [NSMutableArray arrayWithArray:array];

NSMutableArray *result = [array mutableCopy]; //recommended
+2

... , initWithObjects . , , , "" "" . , , initWithArray addObjectsFromArray. ( , , NSMutableArray ( ) )

, initWithObjects, , . (docs) , ...

NSMutableArray *objectsToAdd = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", nil];
+1

The problem may be that the local declaration liston line 4 conflicts with this property.

0
source

All Articles