我遇到了第二頁中的表格視圖在第一頁導航後無法顯示的問題。導航後無法顯示錶格視圖
的第一個頁面重定向代碼爲:
- (IBAction)searchProducts:(id)sender {
ProductsViewController *proViewController = [[ProductsViewController alloc] init];
[self.navigationController pushViewController:proViewController animated:YES];
}
在productsViewController:
#import "ProductsViewController.h"
#import "OriginViewController.h"
#import "Product.h"
@interface ProductsViewController()
@end
@implementation ProductsViewController
NSArray *products;
- (void)viewDidLoad {
[super viewDidLoad];
Product *product1 = [Product new];
product1.name = @"馬克杯";
product1.detail = @"¥57.00 - 64.00";
product1.imageFile = @"cup1.jpg";
products = [NSArray arrayWithObjects:product1, nil];
UIEdgeInsets inset = UIEdgeInsetsMake(5, 0, 0, 0);
self.tableView.contentInset = inset;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return products.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"INIT CELL.");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Product *product = [products objectAtIndex:indexPath.row];
UIImageView *productImageView = (UIImageView *)[cell viewWithTag:100];
productImageView.image = [UIImage imageNamed:product.imageFile];
UILabel *productNameLabel = (UILabel *)[cell viewWithTag:101];
productNameLabel.text = product.name;
UILabel *productDetailLabel = (UILabel *)[cell viewWithTag:102];
productDetailLabel.text = product.detail;
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
兩點可以肯定:
- 的cellForRowAtIndexPath方法已被調用。
- ViewDidLoad已被調用。
有人對我有提示嗎?謝謝。
如果我在產品控制器的第一頁和'模態'中添加了按鈕,它工作正常。 – Linqtoxml
在調用viewDidLoad之後檢查self.view.frame。 – ninjaproger
檢查表視圖框架。 – vojer