0

我设置了文本和图像,它工作正常,但是如何为我的 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
4

1 回答 1

0

查看使用NSDateFormatter将日期转换为字符串stringWithFormat:并将整数转换为字符串。然后您可以将字符串设置为标签的文本。

查看内容以了解有关日期格式化程序和相关复杂性的更多信息。


NSString *numberText = [NSString stringWithFormat:(@"%d", integerValue];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *dateText = [dateFormatter stringFromDate:dateValue];
于 2013-08-15T09:04:48.547 回答