I have an Objective-C class that is a subclass of UIViewController. This isn't my main view, but it is accessed when a button is pushed from ViewController through segue in StoryBoard. They are both attached to a navigation controller so they switch around fine. However, I have a problem. In my "DisplayView.m" file (the second view), I make some calculations and want to set the text of a label. I know that there aren't any problems with the calculation portion of the code, because when I NSLog the string, it comes out fine. However, the label does not change. This is my setup for DisplayView scene in Storyboard:
- Custom class of "DisplayView" set
- Label that is linked to IBOutlet
Here's my imp file for DisplayView.m if that helps. Please let me know if you need any additional details. Things that I've tried:
- Creating a new method to print the text
- Logging the output that is supposed to show up, to the console (works perfect)
- Trying a different label
- Trying to use the label objects without @property
- Trying to setText a non formatted string
None of these tests really worked, and I can't seem to find what the problem is. The new view simply loads without the label. However, if I change the label text in StoryBoard, it does show up. It just isn't showing up any of the values from my code.
DisplayView.m
#import "DisplayView.h"
@interface DisplayView ()
@end
@implementation DisplayView
@synthesize months,days,seconds;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)calc:(int)m with:(int)d andWith:(int)y {
NSString* bday = [NSString stringWithFormat:@"%i-%i-%i 00:00:00 +0000",m,d,y];
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"LL-dd-yyyy 00:00:00 +0000"];
NSDate *date1 = [formatter dateFromString:bday];
NSDate *date2 = [NSDate date];
NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1];
int numberOfDays = secondsBetween/86400;
[days setText:@"asdadas"];
}
@end
DisplayView.h
#import <UIKit/UIKit.h>
@interface DisplayView : UIViewController {
IBOutlet UILabel* months;
IBOutlet UILabel* days;
IBOutlet UILabel* seconds;
}
-(void)calc:(int)m with:(int)d andWith:(int)y;
@property UILabel* months;
@property UILabel* days;
@property UILabel* seconds;
@end