UIRefreshControl在UITableViewController中处于错误的位置

时间:2014-01-24 16:23:57

标签: ios objective-c uitableview uirefreshcontrol

我在UIRefreshControl上看到了很多问题,而且我的UITableViewController也遇到了问题。问题是如此随机发生,从此我无法弄清楚为什么或如何发生。

问题是,有时当你向下滚动tableView时,UIRefreshControl出现在错误的位置,看起来像在tableView本身之上/之上。我附上了问题的截图,我的代码也用于添加UIRefreshControl以及它的刷新方法。

感谢您提供的任何帮助!

enter image description here

- (void)viewDidLoad
{
    self.refreshControl = [[UIRefreshControl alloc] init];

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

    [self.tableView addSubview:self.refreshControl];

    self.tableView.tableFooterView = [[UIView alloc] init];
}

- (void)refreshing:(UIRefreshControl*)refreshControl
{
    [refreshControl beginRefreshing];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    [refreshControl endRefreshing];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 }

3 个答案:

答案 0 :(得分:26)

这是iOS7的已知错误;有时,刷新控件被错误地放在视图层次结构的前面而不是后面。您可以通过在布局后将其发送回来来解决部分问题:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    [self.refreshControl.superview sendSubviewToBack:self.refreshControl];
}

动画仍然不完美,但至少它仍然会低于表格视图。请为此问题打开bug report with Apple

此外,如另一个答案所述,您不应自行将刷新控件添加到视图层次结构中。表视图控制器将为您执行此操作。但这不是问题所在。

Swift版本

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    refreshControl?.superview?.sendSubview(toBack: refreshControl!)
}

答案 1 :(得分:13)

我遇到了同样的问题并用它修好了:

-- this on top 
IF (SELECT OBJECT_ID('tempdb..#tmpErrors')) IS NOT NULL DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
GO
BEGIN TRANSACTION
GO

insert into Table1 (Col1) values (1)
GO
IF @@ERROR <> 0 AND @@TRANCOUNT > 0 BEGIN ROLLBACK;END
IF @@TRANCOUNT = 0 BEGIN INSERT  INTO #tmpErrors (Error) VALUES (1); BEGIN TRANSACTION;END
GO

insert into Table1 (Col1) values (2/0)
GO
IF @@ERROR <> 0 AND @@TRANCOUNT > 0 BEGIN ROLLBACK;END
IF @@TRANCOUNT = 0 BEGIN INSERT  INTO #tmpErrors (Error) VALUES (1); BEGIN TRANSACTION;END
GO

insert into Table1 (Col1) values (3)
GO
IF @@ERROR <> 0 AND @@TRANCOUNT > 0 BEGIN ROLLBACK;END
IF @@TRANCOUNT = 0 BEGIN INSERT  INTO #tmpErrors (Error) VALUES (1); BEGIN TRANSACTION;END
GO

-- this at the end 
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT N'The transacted portion of the database update succeeded.'
COMMIT TRANSACTION
END
ELSE PRINT N'The transacted portion of the database update failed.'
GO
DROP TABLE #tmpErrors
GO

不是添加子视图而是将refreshControl指定为backgroundView

答案 2 :(得分:0)

覆盖func viewDidLayoutSubviews(){ super.viewDidLayoutSubviews() refreshControl?.superview?.sendSubview(toBack:refreshControl!) }