- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用refreshControl通过代码完成所有操作,当我拉动tableView并调用服务器时出现问题。它告诉我这个错误:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds for empty array'
当我运行这个简单的应用程序时,我会观察 TableView 中的数据。我不知道为什么会出现这个问题。
这是代码:
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray * data;
@property (nonatomic, strong) UIRefreshControl *spinner ;
@end
@implementation YPProjectListViewController
@synthesize tableView;
@synthesize data;
@synthesize spinner;
- (void)viewDidLoad {
[super viewDidLoad];
spinner = [[UIRefreshControl alloc]initWithFrame:CGRectMake(130, 10, 40, 40)];
[self loadProjectsFromService];
[spinner addTarget:self action:@selector(loadProjectsFromService) forControlEvents:UIControlEventValueChanged];
[tableView addSubview:spinner];
}
-(void)loadProjectsFromService{
[spinner beginRefreshing];
self.data = [[NSMutableArray alloc] init];
[self.view addSubview:self.tableView];
__weak typeof(self) weakSelf = self;
successBlock = ^(NSMutableArray *newData) {
if ([newData count] > 0) {
[weakSelf refreshData:newData];
}
};
[spinner endRefreshing];
[ypNetManager getProjectListWithSuccessBlock:successBlock error:NULL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Custom getter
- (UITableView *)tableView {
//custom init of the tableview
if (!tableView) {
// regular table view
tableView = [[UITableView alloc] initWithFrame:UIEdgeInsetsInsetRect(self.view.bounds, tableViewInsets) style:UITableViewStylePlain];
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
tableView.delegate = self;
tableView.dataSource = self;
tableView.backgroundColor = [UIColor clearColor];
return tableView;
}
return tableView;
}
#pragma mark - Private methods
- (void)refreshData:(NSMutableArray *)newData {
NSLog(@"data %@", newData);
self.data = newData;
[self.tableView reloadData];
}
最佳答案
我认为您从服务器获取数据没有任何问题。您可能做错的唯一一件事是在重新初始化 self.data 时不刷新 tableView。
当您下拉并释放 TableView 时,需要显示超出视口(viewport)的第 6 个 tableView 单元格,并且您的单元格需要数据中的第 6 个对象,但您的数据不再存在。
只需插入以下内容。
-(void)loadProjectsFromService{
[spinner beginRefreshing];
self.data = [[NSMutableArray alloc] init];
[self.tableView reloadData]; //Insert table reload here.
//... rest of your code ...
}
关于ios - 通过代码错误使用refreshcontrol刷新tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18664289/
我正在使用 RefreshControl列表中的组件在半透明的 app-header-bar 下方滚动。 我唯一的问题是 RefreshControl 出现在半透明标题下方。我真正想要的是能够偏移 R
我为我的 tableview 实现了一个 refreshcontrol,它工作正常。但我想实现调用另一个类在该类中执行进程。我希望我的 refreshcontrol 应该等到那个类的执行。 例如:我在
我正在尝试将refreshControl连接到Rest api,以便每次刷新时都会更新内容。然而,即使它有效,当您释放刷新控件时,它似乎会导致非常滞后且不流畅的体验。这是为什么? 刷新时调用的方法 f
刷新进度完成后,我的刷新控件不会消失。它保持动画,即使我调用了 endRefreshing()。 import UIKit class MyTableViewController: UITableVi
我有一个带有 refreshControl 属性的 ScrollView 的屏幕。结果是,当我刷新屏幕时,屏幕的全部内容都向下移动了几个位置。如果我再次刷新,它会继续下降,依此类推。 此屏幕截图是在刷
应用程序选项卡使用刷新按钮来更新列表,效果很好。尝试使用“下拉刷新”,但根本不起作用。 protocol StaffHistoryDelegate: class { func updateLi
我有一个带有刷新控件的 UITableViewController。当你向下拉时,它工作正常——微调器旋转,标题显示,一切正常。但是,当我使用以下代码以编程方式触发控件时,属性标题不会显示: -(vo
我有这条线 self.refreshControl = [[UIRefreshControl alloc] init]; 但它不被识别,我得到一个编译错误: property refreshContr
我有一个管理大量单元格的 UICollectionView。当我删除一个单元格时,我希望该单元格随 refreshControl 一起消失。但我不明白为什么 reloadData 不起作用。如果有人可
我正在使用 RefreshControl 在按下按钮后启动刷新屏幕,代码如下。但是,即使设置了刷新变量的状态,刷新也不会开始。 const [refresh, setRefresh] = useSta
我有一个 TableView,我在其中从 api 获取数据。在获取/显示数据和分页/无限滚动方面一切正常。但是,当我尝试使用我的 RefreshControl 时,它崩溃并出现错误: Array in
在搜索过程中,我想禁用下拉刷新机制。所以我禁用了刷新控件并将其删除。但是当下拉刷新时会调用 beginRefresh 方法,单元格会保持下拉状态 2 秒,就像刷新一样。 func searchBarS
我正在使用这个 tutorial使用 RefreshControl 实现下拉刷新行为。我正在使用 导航栏。使用普通标题时一切正常。但是,当使用“首选大标题”时,它无法正常工作,如您在以下视频中所见。任
我有一个 FlatList使用标准 RefreshControl ,像这样: } renderItem={({ item, index }) => ()} /> 这会在执行下拉刷新操作时呈现
编辑:React Native 似乎有一个错误。我在 GitHub 上创建了一个错误。求解答的各位:目前好像没有。 https://github.com/facebook/react-native/i
我使用 tableview 开发应用程序,用户可以在其中拉动以刷新。 当我下拉表格时,标题和刷新控件之间有额外的空间。 我这样设置 UIRefreshcontrol 和标题背景 viewDidLoad
我写了一个扩展,允许我在 UIViewController 中的常规 tableView 上显示 refreshControl。下面的代码在 viewDidLoad() 和拉动刷新时完美运行。 扩展名
我的 View 中有一个可滚动的内容。我想在其中添加拉动刷新。我尝试添加但未触发操作。 我尝试了很多方法并重新搜索,但没有一种对我有用。我将 iOS 10 作为最低部署目标。 尝试1: let ref
我使用 Firebase 作为我的数据结构。我在 UITableView 的 refreshControl 中使用完成处理程序,以便在从 Firebase 加载完所有数据后停止刷新。 override
从 react-native@0.26 升级后,RefreshControl 的事件指示器有时会出现在 iOS 上的 ScrollView 的右上角。我按照文档所述正确使用 RefreshContro
我是一名优秀的程序员,十分优秀!