Setting the UI Labels of NSTextfield dynamically in cocoa
I need to set the labels of the UI dyanmically.. I want be read the text from an xml file and would like to set the text to the controls in the NIB.
I guess i can recognise the conrol by using the TAG attribute of the control.
Now i would like to get all the obje开发者_开发百科cts in the window(controls in the Nib) into an array?
Please suggest me on this.
In your code you'll want to create a link to your control. In xcode, in your .h file put something like:
@interface Mycontroller : UIViewController {
IBOutlet UILabel *namelabel;
}
@property (nonatomic, retain) IBOutlet UILabel *namelabel;
-(void)ChangeName:(NSString *)toName;
@end
Then in your .m file put something like:
@implementation ProjectCell
@synthesize namelabel;
-(void)ChangeName:(NSString *)toName {
[namelabel setText:@"your new string"];
}
You then want to open your nib in interface builder. Select your label and go to the inspector (Tool Menu > Inspector). Go to the Connections tab (blue circle w/ white arrow, and then click and drag the circle by New References Outlet from there to File's Owner in the nib window. Select "namelabel" from the popup. They're now linked and changing namelabel in code will change that specific label that you setup in interface builder.
I agree with the above soultion....
I had to set the title of each textfield and buttons in applicationdidFinishLaunching function.
精彩评论