【问题标题】:activity indicator in didSelectRowAtIndexPathdidSelectRowAtIndexPath 中的活动指示器
【发布时间】:2011-05-20 06:52:18
【问题描述】:

i was trying to animate the UIActivityindicator at didSelectRowAtIndexPath i.e when row is selected it should start animating until other view is not loaded.我正在尝试代码,但它什么也没做,求助!!!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self. indicator stopAnimating];
        if(bdvController == nil)
        bdvController = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:[NSBundle mainBundle]];

        if(indexPath.section == 0)
    {       
        Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
        bdvController.aBook = aBook;
    }
    else if(indexPath.section == 1)
    {
        Book *aBook = [appDelegate.books objectAtIndex:indexPath.row+5*indexPath.section];
    bdvController.aBook = aBook;
    }
    [self.navigationController pushViewController:bdvController animated:YES];
 }


- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.indicator startAnimating];
    return indexPath;

}

【问题讨论】:

  • 我觉得这个[self.indicator.startAnimating];应该是[self.indicator startAnimating];
  • @Nick:是的,我看到了……这是我的错误。它应该像你推荐的那样。

标签: iphone


【解决方案1】:


创建一个 NSThread 作为调用选择器,如下所示:

[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) 
                         toTarget:self 
                       withObject:nil];    
// Your code    
[spinner stopAnimating];    
[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES]; 

threadStartAnimating:

-(void)threadStartAnimating:(id)data    
{    
    [spinner startAnimating];    
}  

【讨论】:

  • 它没有做我需要的..我认为 Bharat 说的是正确的!让我检查一下是否根据 Bharat。
  • @user720235:现在工作了吗?如果没有,那么如果您可以粘贴更多代码,我们将能够追踪问题...
【解决方案2】:

首先 [self.indicator.startAnimating];你想在这条线上做什么?您是在访问属性还是调用方法。 而且我认为它将等待 didSelectRow 方法完成以显示指示符。也许您可以尝试在

中显示指标
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

并在

中进行处理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

因为您没有粘贴与指标创建相关的代码。希望您已将表格视图单元格的选择样式设置为 UITableViewCellSelectionStyleNone 并为指示器视图设置了适当的框架。

【讨论】:

  • j: 那边搞错了。我观察到并纠正了它。我想你是对的 。行!我正在尝试在 NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 中执行此操作。
  • -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { [indicator startAnimating];返回索引路径; } 什么都没发生
  • 在 willSelectRowAtIndex 方法中我必须写哪些代码行
  • 这对我不起作用..我认为你最好检查一下stackoverflow.com/questions/6342553/…
猜你喜欢
  • 2011-09-14
  • 2019-10-23
  • 2016-05-23
  • 1970-01-01
  • 2011-06-28
  • 2012-06-08
  • 2010-11-08
  • 2011-09-12
  • 1970-01-01
相关资源
最近更新 更多