我是 iPhone 新手,我正在创建一个应用程序,将国家名称和他们的国旗显示为缩略图。问题是所有图像的大小都不相同,因此输出不可预测。
代码如下
.h 文件
IBOutlet UILabel *countryLabel;
IBOutlet UIImageView *thumbnailView;
IBOutlet UILabel *populationLable;
.m 文件
#import "TextFieldAlertViewController.h"
@implementation TextFieldAlertViewController
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
return cell;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView {
}
- (void)viewDidLoad {
[super viewDidLoad];
tableData = [NSArray arrayWithObjects:@"Australia", @"Brazil",@"China", @"Denmark", @"England", @"France", @"Germany", @"Hong Kong", @"India", @"Japan", @"Korea", @"Labanon", @"Malasiya", @"Niegiria", @"Peru", @"Swidden", nil];
thumbnails = [NSArrayarrayWithObjects:@"aus.png",@"br.png",@"ch.png",@"dk.png",@"eng.png",@"fr.png", @"ger.png",@"hk.png",@"in.png",@"jp.png",@"ko.png",@"lb.png",@"my.png",@"ng.png",@"pe.png",@"sw.png",nil];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
@end