2014-02-27 33 views
0

我想要制作一个非常简单的iOS应用程序,其中在MutableArray中创建一个整数。 整数必须出现在自定义视图控制器的标签中。这里是我的代码:不能在一个标签中显示一个整数

@interface Photo : NSObject 

@property (nonatomic) NSString *name; 
@property (nonatomic) NSString *filename; 
@property (nonatomic) NSString *naam; 
@property (nonatomic) int  leeftijd; 
@property (nonatomic) NSString *herkomst; 
@property (nonatomic) NSString *club; 

@end 

我的自定义TableViewController与一个mutableArray。

@interface PhotosTableViewController() { 
    NSMutableArray *photos; 
} 

@end 

@implementation PhotosTableViewController 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.title = @"Soccer Players"; 

    // Create an array 
    photos = [[NSMutableArray alloc]init]; 

    Photo *pic = [[Photo alloc]init]; 
    pic.name = @"Ronaldo"; 
    pic.filename = @"ronaldo"; 
    pic.naam = @"Christano Ronaldo"; 
    pic.leeftijd = 29; 
    pic.herkomst = @"Portugal"; 
    pic.club = @"Real Madrid"; 

    [photos addObject:pic]; 

,最后我的自定义视图控制器

@interface DisplayViewController() 
@property (weak, nonatomic) IBOutlet UIImageView *currentImage; 
@property (weak, nonatomic) IBOutlet UILabel *nameLabel; 
@property (weak, nonatomic) IBOutlet UILabel *ageLabel; 
@property (weak, nonatomic) IBOutlet UILabel *countryLabel; 
@property (weak, nonatomic) IBOutlet UILabel *clubLabel; 

@end 

@implementation DisplayViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIImage *image = [UIImage imageNamed:self.currentPhoto.filename]; 
    [self.currentImage setImage:image]; 
    self.nameLabel.text = [self.currentPhoto naam]; 
    self.ageLabel.text = [self.currentPhoto leeftijd]; 
    self.countryLabel.text = [self.currentPhoto herkomst]; 
    self.clubLabel.text = [self.currentPhoto club]; 
} 

不知道我做错了。我给了整数一个Property,给了它一个数量en在一个标签中声明。必须是非常愚蠢的东西,但无法在网络上看到解决方案。

感谢您的帮助!

+0

如果答案之一是有用的,请接受它。如果没有 - 请澄清你的问题。 – Avt

回答

0

整数不会自动转换为NSString的。更改

self.ageLabel.text = [self.currentPhoto leeftijd]; 

self.ageLabel.text = [[self.currentPhoto leeftijd] description]; 

self.ageLabel.text = [NSString stringWithFormat:@"%i", [self.currentPhoto leeftijd]]; 
+0

感谢分享男士!非常愚蠢的错误! (y)的 – SwingerDinger

2

你应该 '转换' 诠释为字符串:

self.ageLabel.text = [NSString stringWithFormat:@"%d", [self.currentPhoto leeftijd]]; 
0

拉布勒只显示NSString所以你转换your int to NSString ..

self.ageLabel.text = [NSString stringWithFormat:@"%d", [self.currentPhoto leeftijd]];