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

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
not sure how to do this properly, although i believe it's easy (or maybe it's more complex then i assume)...

Code:
- (id)imageBrowser:(IKImageBrowserView *) view itemAtIndex:(int) index
	{
	return [images objectAtIndex:index];
	}

- (void)imageBrowser:(IKImageBrowserView*)view removeItemsAtIndexes: (NSIndexSet*)indexes
	{
	[images removeObjectsAtIndexes:indexes];
	}
		
- (IBAction)removeSwatchButton:(id)sender
	{
	NSLog (@"Remove Button");
	[self imageBrowser:(IKImageBrowserView*)view removeItemsAtIndexes: (NSIndexSet*)indexes];
	}

so i'm trying to call the second method from the third action method... both are in the same class... compiler states that "view" and "indexes" are undeclared... i've included the first method to show that the first and second are similar, so i can't simply write [self imageBrowser:nil];, which is what i often do for calling other functions that don't have lots of instance variables and other call functions attached.
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
Without knowing more, I'd say the compiler is right... view and indexes aren't declared when you pass them into the method from the IBAction.

What view and what indexes are you trying to pass? Where do they live? Are they instance members?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Hm. Not sure what images is, and it doesn't seem like view is used at all in the first two functions. In the third function... the only local variable you have is the argument sender. How do you know what NSIndexSet you want to remove? You don't have any NSIndexSet declared in this function, so you have nothing to pass to the second function.

Code:
NSIndexSet *myIndexes = [NSIndexSet indexSetWithIndex:[sender intValue]];
[self imageBrowser:nil removeItemsAtIndexes:myIndexes];

would work.

Code:
[self imageBrowser:nil removeItemsAtIndexes:nil];
should work also, but... doesn't make much sense.

-Lee
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Hm. Not sure what images is, and it doesn't seem like view is used at all in the first two functions. In the third function... the only local variable you have is the argument sender. How do you know what NSIndexSet you want to remove? You don't have any NSIndexSet declared in this function, so you have nothing to pass to the second function.

Code:
NSIndexSet *myIndexes = [NSIndexSet indexSetWithIndex:[sender intValue]];
[self imageBrowser:nil removeItemsAtIndexes:myIndexes];

would work.

Code:
[self imageBrowser:nil removeItemsAtIndexes:nil];
should work also, but... doesn't make much sense.

-Lee

thanks for the responses...

lee, neither worked... i'm using apple's code from their ImageBrowser application, which is a simplistic look at the IKImageBrowser class... the problem is that i'm not so strong with understanding what exactly is going on behind the scenes...

at first i tried cheating by simply adding a button with a delete key equivalent, as when the user selects items in the image browser, they are removed by pressing delete... unfortunately for me it didn't work...

i've attached the class files hoping you or someone doesn't mind taking a quick look...my IBActions are at the very end of the the implementation file...
 

Attachments

  • SwatchController.zip
    3.2 KB · Views: 106

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Without knowing more, I'd say the compiler is right... view and indexes aren't declared when you pass them into the method from the IBAction.

What view and what indexes are you trying to pass? Where do they live? Are they instance members?

the index is indexing the NSMutableArray *images inside the IKImageBrowser... below is the datasource section of the code snip from apple's ImageBrowser example:

Code:
#pragma mark IKImageBrowser DataSource

- (int)numberOfItemsInImageBrowser:(IKImageBrowserView*)view
	{
	return [images count];
	}

- (id)imageBrowser:(IKImageBrowserView *) view itemAtIndex:(int) index
	{
	return [images objectAtIndex:index];
	}

- (void)imageBrowser:(IKImageBrowserView*)view removeItemsAtIndexes: (NSIndexSet*)indexes
	{
	[images removeObjectsAtIndexes:indexes];
	}

- (BOOL)imageBrowser:(IKImageBrowserView*)view moveItemsAtIndexes: (NSIndexSet*)indexes toIndex:(unsigned int)destinationIndex
	{
	NSInteger index;
	NSMutableArray *temporaryArray;

	temporaryArray = [[[NSMutableArray alloc] init] autorelease];

	for (index = [indexes lastIndex]; index != NSNotFound; index = [indexes indexLessThanIndex:index])
		{
		if (index < destinationIndex)
			{
			destinationIndex --;
			}
			
		id obj = [images objectAtIndex:index];
		[temporaryArray addObject:obj];
		[images removeObjectAtIndex:index];
		}

	NSInteger n = [temporaryArray count];
	for (index = 0; index < n; index++)
		{
		[images insertObject:[temporaryArray objectAtIndex:index] atIndex:destinationIndex];
		}

	return YES;
	}
	
- (void)updateDatasource
	{
	[images addObjectsFromArray:importedImages];
	[importedImages removeAllObjects];
	[imageBrowser reloadData];
	}

and so now i'm trying to somehow call on the index with my IBAction, and removeObjectAtIndex:index whatever is selected inside the image browser. currently, i can simply press either of the delete buttons on the keyboard and it will remove all selected objects from the IKImageBrowser, so i'm assuming what i'm trying to accomplish wouldn't be very difficult if i had more experience.

Code:
- (IBAction)removeSwatchButton:(id)sender
	{
	NSIndexSet *myIndexes = [NSIndexSet indexSetWithIndex:[sender intValue]];
	[self imageBrowser:nil removeItemsAtIndexes:myIndexes];
	[self updateDatasource];
	}

this code doesn't return any warning or errors at compile, but it doesn't work as expected.

if i add an object to the imagebrowser, then highlight it, then try press the IBAction-delete-button (once) i get the following error in the console:

-[NSCFArray removeObjectsAtIndexes:]: the last index (1) must be less than the count (1).

however, if i press the IBAction-delete-button again, the object disappears.

i can not seem to delete numerous selections at once with the IBAction-delete-button. if i highlight a group of 3 recently added items, i have to press the IBAction-delete-button 3 times as they will only disappear one at a time (in a seemingly random order).
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Code:
- (IBAction)removeSwatchButton:(id)sender
	{
	NSIndexSet *myIndexes = [NSIndexSet indexSetWithIndex:[sender intValue]];
	[self imageBrowser:nil removeItemsAtIndexes:myIndexes];
	[self updateDatasource];
	}

this code doesn't return any warning or errors at compile, but it doesn't work as expected.

if i add an object to the imagebrowser, then highlight it, then try press the IBAction-delete-button (once) i get the following error in the console:

-[NSCFArray removeObjectsAtIndexes:]: the last index (1) must be less than the count (1).

however, if i press the IBAction-delete-button again, the object disappears.

i can not seem to delete numerous selections at once with the IBAction-delete-button. if i highlight a group of 3 recently added items, i have to press the IBAction-delete-button 3 times as they will only disappear one at a time (in a seemingly random order).
It's the [sender intValue] bit that's the problem - you're getting the intValue of the delete button (which is the 'sender' object)- which is almost certainly not what you want.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
It's the [sender intValue] bit that's the problem - you're getting the intValue of the delete button (which is the 'sender' object)- which is almost certainly not what you want.

humm... so what should it be? how can i make my IBAction...

Code:
- (IBAction)removeSwatchButton:(id)sender
	{
	NSIndexSet *myIndexes = [NSIndexSet indexSetWithIndex:[sender intValue]];
	[self imageBrowser:nil removeItemsAtIndexes:myIndexes];
	[self updateDatasource];
	}

...manage the same thing as this, or call this:

Code:
- (void)imageBrowser:(IKImageBrowserView*)view removeItemsAtIndexes: (NSIndexSet*)indexes
	{
	[images removeObjectsAtIndexes:indexes];
        //"images" is an instance of NSMutableArray
	}

?
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Try this
Code:
- (IBAction)removeSwatchButton:(id)sender
	{
	NSIndexSet *myIndexes = [imageView selectionIndexes];
	[self imageBrowser:nil removeItemsAtIndexes:myIndexes];
	[self updateDatasource];
	}
where imageView is the IKImageBrowserView instance in your code
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Try this
Code:
- (IBAction)removeSwatchButton:(id)sender
	{
	NSIndexSet *myIndexes = [imageView selectionIndexes];
	[self imageBrowser:nil removeItemsAtIndexes:myIndexes];
	[self updateDatasource];
	}
where imageView is the IKImageBrowserView instance in your code

works perfectly! thanks cavaman! :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.