为什么只调用一次 UITableView Delegate 方法?
Why UITableView Delegate methods are called only single time?
我正在尝试在我的应用程序中实现选项卡栏控制器 UITableView.I 有三个选项卡 items.And 这是 Product Tab. I am adding my product to mycart. And after adding two products in my cart this is my MyCart Tab 的屏幕截图。但是在返回到“产品”选项卡并删除或添加任何产品并返回到“我的购物车”选项卡后,它没有变化。我在 viewWillAppear() 方法中加载了所有数据。使用断点我发现我的 UITableView 委托方法只被调用一次,而不是每次我更改选项卡项时都被调用。
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
handler = [delegate getHandler];
allProducts = [handler getAllProducts];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
productDataModel = [allProducts objectAtIndex:indexPath.row];
addToCartFlagNumber = (NSNumber*)productDataModel.productAvailability;
if([addToCartFlagNumber integerValue]){
static NSString *simpleTableIdentifier = @"ProductListTableViewCell";
ProductListTableViewCell *cell = (ProductListTableViewCell*) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.productListNameLabel.text = productDataModel.productName;
cell.productListImageView.image = [UIImage imageNamed:productDataModel.productImageName];
cell.productListDescriptionLabel.text = productDataModel.productDescription;
cell.addToCartButton.tagValue = [productDataModel.productID integerValue];
cell.addToCartButton.flagValue = 0;
return cell;
}
else{
static NSString *simpleTableIdentifier = @"UpcomingProductListTableViewCell";
UpcomingProductListTableViewCell *cell = (UpcomingProductListTableViewCell*) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.productListNameLabel.text = productDataModel.productName;
cell.productListImageView.image = [UIImage imageNamed:productDataModel.productImageName];
cell.productListDescriptionLabel.text = productDataModel.productDescription;
return cell;
}
}
在所有三个选项卡中 viewController 的 viewWillAppear 方法中使用以下代码。
[tableView reloadData];
我正在尝试在我的应用程序中实现选项卡栏控制器 UITableView.I 有三个选项卡 items.And 这是 Product Tab. I am adding my product to mycart. And after adding two products in my cart this is my MyCart Tab 的屏幕截图。但是在返回到“产品”选项卡并删除或添加任何产品并返回到“我的购物车”选项卡后,它没有变化。我在 viewWillAppear() 方法中加载了所有数据。使用断点我发现我的 UITableView 委托方法只被调用一次,而不是每次我更改选项卡项时都被调用。
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
handler = [delegate getHandler];
allProducts = [handler getAllProducts];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
productDataModel = [allProducts objectAtIndex:indexPath.row];
addToCartFlagNumber = (NSNumber*)productDataModel.productAvailability;
if([addToCartFlagNumber integerValue]){
static NSString *simpleTableIdentifier = @"ProductListTableViewCell";
ProductListTableViewCell *cell = (ProductListTableViewCell*) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.productListNameLabel.text = productDataModel.productName;
cell.productListImageView.image = [UIImage imageNamed:productDataModel.productImageName];
cell.productListDescriptionLabel.text = productDataModel.productDescription;
cell.addToCartButton.tagValue = [productDataModel.productID integerValue];
cell.addToCartButton.flagValue = 0;
return cell;
}
else{
static NSString *simpleTableIdentifier = @"UpcomingProductListTableViewCell";
UpcomingProductListTableViewCell *cell = (UpcomingProductListTableViewCell*) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.productListNameLabel.text = productDataModel.productName;
cell.productListImageView.image = [UIImage imageNamed:productDataModel.productImageName];
cell.productListDescriptionLabel.text = productDataModel.productDescription;
return cell;
}
}
在所有三个选项卡中 viewController 的 viewWillAppear 方法中使用以下代码。
[tableView reloadData];