Я бился головой об этом целую неделю, я уверен, что на него уже отвечали, но во всех своих исследованиях я просто запутываюсь все больше и больше.
Я просто пытаюсь использовать строку NSString из класса (BBDate) в UILabel в моем основном UIViewController.
BBDate.h
#import <Foundation/Foundation.h>
@interface BBDate : NSObject {
NSString *dateString;
}
@property (nonatomic, retain) NSString *dateString;
@end
BBDate.m
//just a simple date creation and formatting to try to learn this technique
#import "BBDate.h"
@implementation BBDate
@synthesize dateString;
- (void)createDate; {
NSDate* date = [NSDate date];
//Create the dateformatter object
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
//Set the required date format
[formatter setDateFormat:@"MM-dd-yyyy"];
//Get the string date
NSString *string = [formatter stringFromDate:date];
//Display on the console
NSLog (@"%@",string);
//set variable
dateString = string;
}
@end
UIViewController.h
#import <UIKit/UIKit.h>
#import "BBDate.h"
@interface BBFirstViewController : UIViewController {
UILabel *dateToday;
BBDate *bbDate;
}
@property (nonatomic, retain) IBOutlet UILabel *dateToday;
@property (nonatomic, retain) BBDate *bbDate;
@end
UIViewController.m
#import "BBFirstViewController.h"
#import "BBDate.h"
@implementation BBFirstViewController
@synthesize dateToday, bbDate;
...
//for testing i'm just using viewdidload
- (void)viewDidLoad {
[super viewDidLoad];
dateToday.text = bbDate.dateString;
NSLog(@"%@", bbDate.dateString);
...