【问题标题】:UIRefreshControl crashes while refreshing Tableview Controller刷新 Tableview 控制器时 UIRefreshControl 崩溃
【发布时间】:2013-02-25 22:23:32
【问题描述】:

我无法刷新我的 TVC。当我向下拖动以刷新时,它崩溃了。 图标在那里,但随后它退出了。我敢肯定它很简单。还有一些类似的问题尚未考虑。

取自我的 viewDidLoad 方法体:

refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self
                   action:@selector(refreshInvoked:forState:)
         forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:refreshControl];

refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:title
                                                            attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:13.0]}];
[self refreshFeed];

指的是:

-(void)refreshFeed 
{
   RSSLoader* rss = [[RSSLoader alloc] init];    
   [rss fetchRssWithURL:feedURL
            complete:^(NSString *title, NSArray *results) {
                dispatch_queue_t downloadQueue = dispatch_queue_create("downloader",NULL);
                dispatch_async(downloadQueue, ^{
                _objects = results;
                    [self.tableView reloadData];
                //completed fetching the RSS
                dispatch_async(dispatch_get_main_queue(), ^{
     //               [(HeaderView*)self.tableView.tableHeaderView setText:title];
                    // [(ArticleItem*)self.tableView.]
                });
                });
    }];
}

【问题讨论】:

  • 请在询问崩溃时包含崩溃日志,ACB 可能是对的,但为什么让我们猜测?
  • @jrturton,这是真的。我的回答纯粹是基于一个假设,可能是完全错误的。

标签: iphone ios asynchronous uirefreshcontrol


【解决方案1】:

UIRefreshControl 不是要添加为子视图...这样做会给您带来一些麻烦,您需要在 VC dealloc 上取消注册它的目标...否则您可能会遇到一些问题,当UIRefreshControl 调用您死掉的 VC(因为它不会保留对您的 VC 的弱引用或强引用)

【讨论】:

    【解决方案2】:

    将您的操作方法更改为:

    [refreshControl addTarget:self
                       action:@selector(refreshFeed)
             forControlEvents:UIControlEventValueChanged];
    

    看起来您指向的 refreshInvoked:forState: 不存在于 self 中。

    【讨论】:

    • 你也可以尝试实现- (void)refreshInvoked:(id)sender forState:(UIEvent *)event,保持addTarget部分不变。
    • 答题体的解决方案瞬间解决了问题。现在是完成后关闭 refreshControl 的问题。
    • 很高兴知道这一点。 “现在是在完成后关闭 refreshControl 的问题。” - 你不必关闭它。我会自动回到之前的状态。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多