Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
Hey guys, pretty simple question, I've got an NSArrayController, and I'm trying to somehow get the size of it. Right now I'm trying:

[[stepsController arrangedObjects] count]

But it's returning 0. Any ideas? Thanks! :)
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
Hey guys, pretty simple question, I've got an NSArrayController, and I'm trying to somehow get the size of it. Right now I'm trying:

[[stepsController arrangedObjects] count]

But it's returning 0. Any ideas? Thanks! :)
Dunno, seems like that should work, and I'm pretty sure I'm using exactly that code in one of my projects. Are you absolutely certain you have more than 0 objects being controlled by the controller? Are you maybe using Core Data (where "count" possibly doesn't reflect objects that haven't been fetched from the data store yet)?
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Dunno, seems like that should work, and I'm pretty sure I'm using exactly that code in one of my projects. Are you absolutely certain you have more than 0 objects being controlled by the controller? Are you maybe using Core Data (where "count" possibly doesn't reflect objects that haven't been fetched from the data store yet)?

Thats what I use too... Try checking the filter predicate is nil, then if it's still nil fetch the objects from the data store (Core Data only), see the following code.
Code:
	[arrayController setFilterPredicate:nil];
	if([[arrayController arrangedObjects] count]==0){
		//NSLog(@"no objects");//may be worth uncommenting this.
		[arrayController addObjects:[mObjC executeFetchRequest:[model fetchRequestFromTemplateWithName:@"yourObject"  substitutionVariables:[NSDictionary dictionary]]
															 error:nil]];
	}

EDIT: mObjC is the managedObjectContext and model is the managedObjectModel
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.