【发布时间】:2014-05-11 16:46:21
【问题描述】:
我一直在开发一款 iOS 应用,但在其中一个屏幕上遇到了一些复杂问题。
这个名为“about”的屏幕只有两个标签:它们应该显示当前的用户名和时间。
标签的文本加载良好,但我无法让它们显示带有用户名和当前时间的变量。
这是我的代码:
关于.h
@interface About : UIViewController
@property (weak) IBOutlet UILabel * username;
@property (weak) IBOutlet UILabel * date;
@property (strong, nonatomic) NSString * usuari;
@property (strong, nonatomic) NSString * data;
@property (strong, nonatomic) NSString * name;
@property (strong, nonatomic) NSString * currentTime;
关于.m
#import "About.h"
@interface About()
@end
@implementation About
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel * username = [[UILabel alloc] initWithFrame:CGRectMake(162, 106, 150, 72)];
[self.view addSubview: username];
username.text = @"Usuari: ";
username.numberOfLines = 4;
username.textColor = [UIColor blackColor];
username.text = [NSString stringWithFormat:@"Usuari: ", _usuari];
UILabel * date = [[UILabel alloc] initWithFrame:CGRectMake(160, 261, 1488, 44)];
[self.view addSubview: date];
date.text = @"Hora: ";
date.numberOfLines = 4;
date.textColor = [UIColor blackColor];
date.text = [NSString stringWithFormat:@"Hora: ", _currentTime];
}
-(void) gettingUser
{
[[UIDevice currentDevice] name];
self.username.text = self.name;
}
-(void) gettingTime
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
NSString *currentTime = [dateFormatter stringFromDate:[NSDate date]];
self.date.text = self.currentTime;
//self.date.text = [NSDate date];
//NSTimer schedule interval
//NSDateFormatter alloc
}
@end
你能帮我弄清楚我需要做什么才能让它工作吗?
【问题讨论】:
标签: ios variables nsstring uilabel