我创建了一个包含一些属性的类。在故事板中,我有一个tableview控制器。我想将数据从类传递到tableview。在每个单元格中,我都有一些标签。我想填充数据,但我没有成功使用数组。你能帮我么。
所以我有一个City类,其中包含一些属性。 property1,property2,它们是标签
#import <Foundation/Foundation.h>
@interface DACityObject : NSObject {
NSNumber *ID;
NSString *name;
NSNumber *temperature;
NSNumber *minimumTemperature;
NSNumber *maximumTemperature;
NSString *iconName;
}
@property (strong,nonatomic) NSNumber *ID;
@property (strong,nonatomic) NSString *name;
@property (strong,nonatomic) NSNumber *temperature;
@property (strong,nonatomic) NSNumber *minimumTemperature;
@property (strong,nonatomic) NSNumber *maximumTemperature;
@property (strong,nonatomic) NSString *iconName;
@end
和.m文件
#import "DACityObject.h"
@implementation DACityObject
@synthesize ID,name,temperature,minimumTemperature,maximumTemperature,iconName;
@end
DACityCell.h
#import <UIKit/UIKit.h>
@interface DACityCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *name;
@property (strong, nonatomic) IBOutlet UILabel *temperature;
@property (strong, nonatomic) IBOutlet UILabel *minimumTemperature;
@property (strong, nonatomic) IBOutlet UILabel *maximumTemperature;
@property (strong, nonatomic) IBOutlet UIImageView *iconName;
@end
DACityCell.m
#import "DACityCell.h"
@implementation DACityCell
@synthesize name,temperature,minimumTemperature,maximumTemperature,iconName;
- (void)awakeFromNib {
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = CGRectMake(0,45,75,75);
}
@end
如何为示例3个城市创建数据并将其放在MainController的表格视图中?