基本上我想要做的是我想用数组中的字符串填充表视图。我做了第二个UIviewcontroller和一个自定义单元格,显示图像和另外两个标签。但是当我运行代码时,没有错误消息,但tableview是空白的,几乎就像它根本不识别代码一样。我在.h文件中声明了它的委托和数据源。
#import "ViewController4.h"
#import "Cell.h"
#import "XMLparse.h"
@interface ViewController4 ()
@end
@implementation ViewController4
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(NSMutableArray *)objects {
if (!Datarray) {
Datarray = [[NSMutableArray alloc]init];
}
return Datarray;
}
- (void)viewDidLoad
{
[super viewDidLoad];
Datarray = [[NSMutableArray alloc]initWithObjects:@"USD",@"EUR",@"JPY",@"BGN",@"CZK",@"DKK",@"GBP",@"HUF",@"LTL",@"PLN",@"RON",@"SEK",@"CHF",@"NOK",@"HRK",@"RUB",@"TRY",@"AUD",@"BRL",@"CAD",@"CNY",@"HKD",@"IDR",@"ILS",@"INR",@"KRW",@"MXN",@"MYR",@"NZD",@"PHP",@"SGD",@"THB",@"ZAR", nil];
Tableview.delegate = self;
XMLparse *datee = [[XMLparse alloc]init];
[datee loadDataFromXML];
Date.text = [NSString stringWithFormat:@"Last updated: %@",[datee tid]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableview:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableview numberOfRowsInSection:(NSInteger)section {
return [Datarray count];
}
- (CGFloat)tableView:(UITableView *)tableview heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"Cell";
Cell *cell = (Cell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
// cell.ratename.text = [tableData objectAtIndex:indexPath.row];
// cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
cell.currencyname.text = [Datarray objectAtIndex:indexPath.row];
return cell;
}
@end
答案 0 :(得分:0)
您必须将self
设置为UITableView的datasource属性。我建议您编辑以下代码。
- (void)viewDidLoad
{
[super viewDidLoad];
Datarray = [[NSMutableArray alloc]initWithObjects:@"USD",@"EUR",@"JPY",@"BGN",@"CZK",@"DKK",@"GBP",@"HUF",@"LTL",@"PLN",@"RON",@"SEK",@"CHF",@"NOK",@"HRK",@"RUB",@"TRY",@"AUD",@"BRL",@"CAD",@"CNY",@"HKD",@"IDR",@"ILS",@"INR",@"KRW",@"MXN",@"MYR",@"NZD",@"PHP",@"SGD",@"THB",@"ZAR", nil];
Tableview.delegate = self;
Tableview.dataSource = self; // <---- added code for setting datasource.
XMLparse *datee = [[XMLparse alloc]init];
[datee loadDataFromXML];
Date.text = [NSString stringWithFormat:@"Last updated: %@",[datee tid]];
}