Lefora Free Forum
Loading
692 views

Noob requires help

Page 1
1–4
rookie - member
2 posts

Hi,
    I am very new to learning to program with Cocoa and I am trying to cobble something together from various book and tutorials I have come accross. 

If anyone could take a look at the attached image and advise where I am going wrong, it would be very much appreciated. 

I have a number of sliders and i want the value to automatically update a textfield. Later on i want to perform some mathematical equations with these figures.

?
288 posts

To set the "visible" value in a text control, you should say:
[label1 setStringValue:[NSString stringWithFormat:.... bla bla]];

A few words of encouragement and advice:
1) Controller1.hYou'll need to have label1 declared as IBOutlet NSTextField* label1;AND in InterfaceBuilderYou'll need to connect label1 to the UI

2) Please get hold of Aaron Hillegass' book (3rd Edition)
Cocoa's rather puzzling until you get used to it (then it becomes easy).  Aaron's book is an essential companion on the road to Cocoa Happiness.

3) When you want to connect several controls together to update data in memory and on the UI, you'll find that 'bindings' are your best friend.  This is described in Chapter 7 of the book (his example even uses a slider).

__________________
rookie - member
2 posts


Hi, thanks for the reply, I do believe I have controller.h setup correctly this is how it currently reads (there will be more added to this at some point) just need to get the basics working first. 

#import <Cocoa/Cocoa.h>

@interface Controller1 : NSObject {

    IBOutlet NSTextField *label1;

    IBOutlet NSTextField *label2;

    IBOutlet NSTextField *label3;

    IBOutlet NSTextField *label4;

    IBOutlet NSTextField *output1;

    IBOutlet NSTextField *output2;

    IBOutlet NSSlider *slider1;

    IBOutlet NSSlider *slider2;

    IBOutlet NSSlider *slider3;

    IBOutlet NSSlider *slider4;

}

- (IBAction)changelabel1:(id)sender;

- (IBAction)changelabel2:(id)sender;

- (IBAction)changelabel3:(id)sender;

- (IBAction)changelabel4:(id)sender;

@end


I understand the interface builder part of xcode and have made all of the connections. controller1.m currently reads as 

#import "Controller1.h"

@implementation Controller1

- (IBAction)changelabel1:(id)sender {

    

int slider1value = slider1.value;

[label1 SetStringValue:[NSString stringWithFormat:@"%d", slider1value]];

}

- (IBAction)changelabel2:(id)sender {

    

int slider2value = slider2.value;

label2.text = [NSString stringWithFormat:@"%d", slider2value];

}

- (IBAction)changelabel3:(id)sender {

    

int slider3value = slider3.value;

label3.value

}

- (IBAction)changelabel4:(id)sender {

    

setvalue int label4 = slider4;

}

@end



but I am still getting various warnings on the two lines of code for changelabel1(which links to a nstextfield)


?
288 posts


try:

int slider1value = [slider1 intValue];  // slider1.intValue will probably work
[label1 setStringValue:slider1value]; // not SetStringValue

About the naming conventions used in cocoa.
All Classes Start With A Capital Letter - for example NSTextField
all methods and variables start with a lower case letter:  for example setStringValue

If that doesn't fix it, please zip up the code (delete the build directory first) and email it to me and I'll take a look.   robin@clanmills.com

__________________
Page 1
1–4

Locked Topic


You must be a member to post in this forum

Join Now!