UI活动指示器无法从tableview工作

时间:2013-07-25 15:38:29

标签: ios uistoryboard uiactivityindicatorview

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

执行周期如下:

  • 使用表格视图查看加载
  • 用户点击单元格 - (UIActivityIndi​​cator在此步骤失败以显示或动画显示)
  • 正在收集数据时显示活动指示
  • 使用加载的数据调用新视图
  • 用户点击导航栏中的后退按钮
  • 重复循环

loading object是故事板中的活动指示符链接。

@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中的功能

如果您需要更多信息,请说出来。

任何帮助都会很棒的人

干杯

1 个答案:

答案 0 :(得分:0)

如果我错了,请纠正我,但我找不到任何地方,你已经宣布了活动指标。尝试将此添加到viewDidLoad中,或者开始设置动画

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

希望这有帮助