gpt4 book ai didi

ios - iOS 7 中的下拉刷新

转载 作者:技术小花猫 更新时间:2023-10-29 10:13:41 25 4
gpt4 key购买 nike

我正在尝试让下拉刷新功能在我的 TableView 中在 iOS 7 上正常工作。在 viewDidLoad 上,我有:

self.refreshControl = [[UIRefreshControl alloc] init];

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

然后我运行:

-(void) refreshInvoked:(id)sender forState:(UIControlState)state {
// Refresh table here...
[_allEntries removeAllObjects];
[self.tableView reloadData];
[self refresh];
}

当刷新方法调用的请求完成时,在 didCompleteRequest 代码中,我有:

[self.refreshControl endRefreshing];

在 iOS 6 上,这意味着当您在 table view 上下拉时,它会显示圆形箭头,当您拉动时它会被拉长,拉得足够远后,它会刷新。不过现在,我看不到圆形箭头,只有一个 UIActivityIndi​​cator。它也有时会工作,有时不会。我错过了什么?

最佳答案

在您的 UITableView 中添加 UIRefreshControl...

1) 在 ViewDidLoad..

- (void)viewDidLoad
{
[super viewDidLoad];

//to add the UIRefreshControl to UIView
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Please Wait..."]; //to give the attributedTitle
[refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[tblVideoView addSubview:refreshControl];
}

2) 调用相关方法刷新UITableView数据...

- (void)refresh:(UIRefreshControl *)refreshControl
{
[self refreshTableData]; //call function you want
[refreshControl endRefreshing];
}

或用于 Swift

 let refreshControl : UIRefreshControl = UIRefreshControl.init()
refreshControl.attributedTitle = NSAttributedString.init(string: "Please Wait...")
refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
feedTable.addSubview(refreshControl)

func refresh(refreshControl:UIRefreshControl){
self.refreshTableData()//call function you want
refreshControl.endRefreshing()
}

关于ios - iOS 7 中的下拉刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19913473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com