• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie question (no idea where to start) - Create Interface Programatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question (no idea where to start) - Create Interface Programatically


  • Subject: Re: Newbie question (no idea where to start) - Create Interface Programatically
  • From: email@hidden
  • Date: Wed, 17 Aug 2005 12:47:47 -0400

On Aug 17, 2005, at 12:04 PM, Andrew Filipowski wrote:

I am not even sure where to begin on how to do this. I have an array that I want to iterate through and objects within it that have a certain attribute assigned called siteRankings. If the value of this boolean is true I want to add to my interface a text label and a text box. The label would be the name of the site, and the text box would allow me to input a numeric value for that particular site that is associated with a player that is in a different array.

I created a view in interface builder that is just this, but I am not sure how to add some number of these views into my main document window. Is there a good tutorial out there that can help? I haven't been able to find anything that really helps me. The closest I have come is the core recipes tutorial but it is not very helpful in that regard. Thanks.

What kind of container are you using for this indefinite number of text fields and text boxes? Have you looked at using an NSTableView and adding the programmatically created componetns to that?


In terms of simply programmatically creating the interface elements from the array, you could use a simple "for" loop that accesses the data and builds the components on the fly. For example, in a method:

int i;
NSArray * dataArray = nil; //Get data from somewhere
NSView * myView = nil; //myView should be something connected through your IBOutlet, or created programmatically before the loop.


for (i = 0; i < [dataArray count]; i++) {
NSTextField * textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0,0,100,100)];
[textField setStringValue:[dataArray objectAtIndex:i]];
[textField setEditable:NO];
NSTextField * inputTextField = [[NSTextField alloc] initWithFrame:NSMakeRect(105, 0, 100, 100)];


    [myView addSubview:textField];
    [myView addSubView:inputTextField];

    [textField release];
    [inputTextField release];
}

Does that help any? I just made that code up on the fly, so it is untested and may not work. Also, it doesn't take into account adding more than one of these two controls, as it would add more than one on top of each other, which is why you need some kind of organized interface for your subviews.

If it's Objective-C or programming in general you're new to, the book "Programming in Objective-C" by Kochan is really good, but doesn't cover the Cocoa app kit. If you want more Cocoa focus, I've heard Aaron Hillegrass' book, "Cocoa Programming For Mac OS X," is really good.

Cameron
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Newbie question (no idea where to start) - Create Interface Programatically (From: Andrew Filipowski <email@hidden>)

  • Prev by Date: Re: Core Data SQL store looses data that XML store does not
  • Next by Date: Core Data: using array operators in a fetch spec?
  • Previous by thread: applicationShouldTerminate: & Core Data
  • Next by thread: Re: Newbie question (no idea where to start) - Create Interface Programatically
  • Index(es):
    • Date
    • Thread