Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 5, 2005, 09:49 AM   #1
lostingamma
macrumors member
 
Join Date: Apr 2005
indexed objects in cocoa

is there some way in cocoa to have many diffrent NSImageView objects, and give them a diffrent index? in applescript, i could just do:

Quote:
set contents of image view i to (item theAnswer of theSymbols)
but, in cocoa, u would have to set he outlets, which im not sure how you would do this cocoa, so, that i could referrer to a object in a method
lostingamma is offline   0 Reply With Quote
Old Apr 5, 2005, 10:12 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
You seem to have got very confused. Why do you want multiple NSImageViews. Can you not have a NSArray of NSImages (getting you your indexed access) and set the image view to show the one you want (which is pretty much what your AppleScript seems to do)?
robbieduncan is offline   0 Reply With Quote
Old Apr 5, 2005, 10:28 AM   #3
lostingamma
Thread Starter
macrumors member
 
Join Date: Apr 2005
well

well, there is a image view for each image, and certain images go into certain image views, and if i use and index i can get it so that one image goes into all the image wells that are used for numbers that are divisble by 9, then, the applescriptcode fills in all the other image views with other random images, that way, there is an image next to each number (which is a system text label thing) so that the same image appears next to all the numbers divisble by 9, and the applescript code does this by using indexs of the image views, so that it can refrence to the correct image view just by using an integer, becuase that integer changes while it goes through a repeate statement, here is more of the code:

Quote:
if item 1 of theSymbols is null then --load images if they haven't aleady
repeat with i from 1 to 25
set item i of theSymbols to (load image (i as string) & " copy")
end repeat
end if
if imagesRandomized is false then --shuffle images if they havn't already
load sound "next"
set theAnswer to random number from 1 to 25
tell window windowName
tell drawer "drawer"
repeat with i from 100 to 1 by -1
if ((i - 1) / 9) mod 1 is 0 then
set contents of image view i to (item theAnswer of theSymbols)
else
set theRandom to random number from 1 to 25
if theRandom is equal to theAnswer then
set theOther to random number from 1 to 2
if theOther is equal to 1 then
set contents of image view i to (item theAnswer of theSymbols)
else
set contents of image view i to (item (random number from 1 to 25) of theSymbols)
end if
else
set contents of image view i to (item theRandom of theSymbols)
end if
end if
end repeat
end tell
set imagesRandomized to true
end tell
end if
the code works fine in applescript, im just trying to recreate the program in cocoa
lostingamma is offline   0 Reply With Quote
Old Apr 5, 2005, 11:07 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by lostingamma
well, there is a image view for each image, and certain images go into certain image views, and if i use and index i can get it so that one image goes into all the image wells that are used for numbers that are divisble by 9, then, the applescriptcode fills in all the other image views with other random images, that way, there is an image next to each number (which is a system text label thing) so that the same image appears next to all the numbers divisble by 9, and the applescript code does this by using indexs of the image views, so that it can refrence to the correct image view just by using an integer, becuase that integer changes while it goes through a repeate statement, here is more of the code:



the code works fine in applescript, im just trying to recreate the program in cocoa
Any chance of sentances going forward? Punctuation, like comments in code, make it much easier to read and understand what you are talking about! Once I get home I'll post an XCode project that creates a NSArray of NSImageViews for you...
robbieduncan is offline   0 Reply With Quote
Old Apr 5, 2005, 12:27 PM   #5
lostingamma
Thread Starter
macrumors member
 
Join Date: Apr 2005
well

well, in short, you don't really need an array, atleast, i don't think so. In short, here is an example of what I want to do.

You have 3 textfields.
The outlets are: textField0, textField1, textField2

you would right code sort of like this:

int i; //define the variable
for (i = 0; i < 3; i++) { //set a for statment, that will make i 0 to 2
[textField(i) setObjectValue:i];
}

so, basicly, the i needs to be used to define the textfield. There is no "textField" , all the text fields have numbers after them, and that is what "i" is for. So, the output would be:

textField0 would have the text "0"
textField1 would have the text "1"
textField2 would have the text "2"

If I could figure out how to do that, I could do it in my code. The problem I am having is the "[textField(i)" part. I know that that's not how you would do it, I am not sure how to do it though. I can't find any examples of what I want to do in any books that I have.
lostingamma is offline   0 Reply With Quote
Old Apr 5, 2005, 01:28 PM   #6
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by lostingamma
...
If I could figure out how to do that, I could do it in my code. The problem I am having is the "[textField(i)" part. I know that that's not how you would do it, I am not sure how to do it though. I can't find any examples of what I want to do in any books that I have.
You can't do that. That's why there are no examples of it! Indexed access is for arrays (either of the normal C type or NSArrays). You cannot do that sort of string interpolation in C or Obj-C.

Assuming that you have added all your controls to a container view (or the window) then you can do something like:

Code:
IBOutlet NSView *view

....

int count ;
int found = 0;
NSArray *subviews = [view subviews];
NSView *view;
for (i=0;i<[subviews count];i++)
{
  view = [subviews objectAtIndex:i];
  if ([view isKindOfClass:[NSImageView class])
 {
   // Set the image via found index here
   [view setImage:....];
   found++;
 }
}

...
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Objects in Objective C luke71933 Mac Programming 6 Apr 8, 2014 09:20 AM
OpenGL ES: Vertex Buffer Objects and Vertex Array Objects Blakeasd iPhone/iPad Programming 2 Jul 13, 2013 12:24 AM
Cydia mismatch error, and indexed files failed to load error. Napster100 Jailbreaks and iOS Hacks 6 May 19, 2013 02:31 PM
LR -> PS as smart objects patent10021 Digital Photography 1 Oct 17, 2012 04:44 PM
How to show/hide objects in Cocoa Applescript application sjmonty99 Mac Programming 3 Aug 6, 2012 12:02 PM

Forum Jump

All times are GMT -5. The time now is 02:33 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC