I am very new to objective-c and having a problem to initialize an object in view controller. The problem I am having is that when setTemp method is called, "0" is printed on the screen instead of the value of cTemp I would like it to be. Can anyone help me on this problem?
Below are excerpts of the code I have.
SJT.h
#import <Foundation/Foundation.h>
#import <stdlib.h>
@interface SJT : NSObject {
int cTemp;
}
- (int) newTemp;
@end
SJT.m
#import "SJT.h"
@implementation SJT
- (int) newTemp
{
cTemp = 25 + rand() % 8;
return cTemp;
}
@end
SJTViewController.h
#import <UIKit/UIKit.h>
@class SJT;
@interface SJTViewController : UIViewController {
IBOutlet UILabel *temp;
SJT *sjt;
}
@property (retain, nonatomic) UILabel *temp;
@property (retain, nonatomic) SJT *sjt;
- (IBAction) setTemp: (id) sender;
@end
SJTViewController.m
#import "SJTViewController.h"
#import "SJT.h"
@implementation SJTViewController
@synthesize temp;
@synthesize sjt;
- (IBAction) setTemp: (id) sender
{
NSString *tempText = [[NSString alloc] initWithFormat:@"%d",sjt.newTemp];
temp.text = tempText;
[tempText release];
}
.
.
.
@end