我设置文本和图像工作正常,但如何为我的UI设置日期和整数值。 如何在sqlite iPhone中为我的UI设置日期和整数值?这是我的评论class.h
@interface Comments : NSObject
{
NSInteger iD;
UIImage *photo;
NSString *name;
NSString *descrp;
NSDate *date;
NSString *msg;
NSInteger noofcomm;
NSInteger nooflikes;
}
@property(nonatomic,assign)NSInteger iD;
@property(nonatomic,retain)UIImage *photo;
@property(nonatomic,retain)NSString *name;
@property(nonatomic,retain)NSString *descrp;
@property(nonatomic,strong)NSDate *date;
@property(nonatomic,retain)NSString *msg;
@property(nonatomic,assign)NSInteger noofcomm;
@property(nonatomic,assign)NSInteger nooflikes;
@end
这是我的RootViewController.h
@interface RootViewController : UIViewController
{
NSMutableArray *list;
}
@property(nonatomic,retain)NSMutableArray *list;
@property(weak,nonatomic)IBOutlet UIImageView *image2;
@property(weak,nonatomic)IBOutlet UILabel *name2;
@property(weak,nonatomic)IBOutlet UILabel *descrp2;
@property(weak,nonatomic)IBOutlet UILabel *date2;
@property(weak,nonatomic)IBOutlet UITextView *msg2;
@property(weak,nonatomic)IBOutlet UILabel *comments2;
@property(weak,nonatomic)IBOutlet UILabel *likes2;
@end
这是我的RootViewController.m
#import "RootViewController.h"
#import "Comments.h"
#import "DBClass.h"
@interface RootViewController ()
@end
@implementation RootViewController
@synthesize list;
@synthesize image2;
@synthesize name2;
@synthesize descrp2;
@synthesize msg2;
@synthesize date2;
@synthesize comments2;
@synthesize likes2;
- (void)viewDidLoad
{
DBClass * mywines =[[DBClass alloc] init];
self.list = [mywines getMyComments];
[self.image2 setImage:((Comments *) [self.list objectAtIndex:0]).photo];
[self.name2 setText:((Comments *) [self.list objectAtIndex:0]).name];
[self.descrp2 setText:((Comments *) [self.list objectAtIndex:0]).descrp];
//[self.date2 setDate:((Comments *) [self.list objectAtIndex:0]).date];
[self.msg2 setText:((Comments *) [self.list objectAtIndex:0]).msg];
// [self.comments2 setText:((Comments *) [self.list objectAtIndex:0]).noofcomm];
// [self.likes2 setText:((Comments *) [self.list objectAtIndex:0]).nooflikes];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setImage2:nil];
[self setName2:nil];
[self setMsg2:nil];
[self setDescrp2:nil];
[self setComments2:nil];
[self setLikes2:nil];
[self setDate2:nil];
[super viewDidUnload];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
使用NSDateFormatter
将日期转换为字符串,然后使用stringWithFormat:
将整数转换为字符串。然后,您可以将字符串设置为标签的文本。
查看this以了解有关日期格式化程序和相关复杂性的更多信息。
NSString *numberText = [NSString stringWithFormat:(@"%d", integerValue];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *dateText = [dateFormatter stringFromDate:dateValue];