0

问题是,当用户从表格视图中选择单元格时,我无法让 UI 活动指示器激活动画或显示。

执行周期如下所示:

  • 使用表格视图查看负载
  • 用户单击单元格 - (UIActivityIndi​​cator 在此步骤无法显示或动画)
  • 收集数据时出现活动指示器
  • 使用加载的数据调用新视图
  • 用户从导航栏中单击返回按钮
  • 重复循环

加载对象是情节提要中的活动指示器链接。

@synthesize jsonConnection, bakeryProductArray, bakeryTableView, loading;

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    [self retrieveData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)viewWillAppear:(BOOL)animated
{

    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    loading.hidden = YES;
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}


#pragma mark - UITableView DataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        return [searchResults count];
    }
    else {
    return [bakeryProductArray count];

    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }

    if (tableView == self.searchDisplayController.searchResultsTableView) {
        foodProducts *currentProduct = [searchResults objectAtIndex:indexPath.row];
        cell.textLabel.text = currentProduct.productName;
    }
    else {
    foodProducts *currentProduct = [bakeryProductArray objectAtIndex:indexPath.row];
    cell.textLabel.text = currentProduct.productName;
    cell.detailTextLabel.text = currentProduct.productquantity;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    return cell;

}

#pragma mark - UITableView Delegate methods

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (bakeryTableView == self.searchDisplayController.searchResultsTableView) {
        [self performSegueWithIdentifier: @"bakeryDetails" sender: self];
    }

        detailedViewController *productinfo = [self.storyboard instantiateViewControllerWithIdentifier:@"bakeryDetails"];
        //Retrieve current user array
        foodProducts *currentProduct2 = [bakeryProductArray objectAtIndex:indexPath.row];
        productinfo.productName = currentProduct2.productName;
        productinfo.productImage = currentProduct2.productImgUrl;
        productinfo.productDescription = currentProduct2.productDescription;
        productinfo.productPrice = currentProduct2.productPrice;
        productinfo.productQuantity = currentProduct2.productquantity;
        productinfo.productAllergy = currentProduct2.productAllergy;

        [loading startAnimating];

        [self.navigationController pushViewController:productinfo animated:YES];
        [bakeryTableView deselectRowAtIndexPath:indexPath animated:YES];

}

我检查了明显的东西,例如:

如果活动指示器位于对象后面。未激活 IB 的功能

如果您需要更多信息,请直接说。

任何帮助都会很棒

干杯

4

1 回答 1

0

如果我错了,请纠正我,但我找不到您声明活动指示器的任何地方。尝试将此添加到您的 viewDidLoad 中,或者它开始动画的位置

loading = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
loading.frame =//set frame
[self.view addSubview:loading];
//Or add it to the cell in didselectrow etc

希望这可以帮助

于 2013-07-26T00:15:12.490 回答