Ios 拉动以刷新TableView的问题
我使用两个自定义原型单元格在UITableview中添加了pull-to-refresh,我尝试使用这两种类型的代码一种是通过将UIRefreshcontrol添加为tableview的子视图,另一种是通过UITableViewController 1)UIRefreshcontrol作为tableview的子视图Ios 拉动以刷新TableView的问题,ios,objective-c,iphone,uitableview,uirefreshcontrol,Ios,Objective C,Iphone,Uitableview,Uirefreshcontrol,我使用两个自定义原型单元格在UITableview中添加了pull-to-refresh,我尝试使用这两种类型的代码一种是通过将UIRefreshcontrol添加为tableview的子视图,另一种是通过UITableViewController 1)UIRefreshcontrol作为tableview的子视图 self.refreshControl = [[UIRefreshControl alloc] init]; self.refreshControl.tintColor = [UIC
self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.tintColor = [UIColor blackColor];
[self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[listTable addSubview:self.refreshControl];
2)通过UITableViewController
UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = listTable;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshContacts) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;
但这两种方法似乎都不起作用。查看这些链接以获取信息 范例
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.backgroundColor = [UIColor clearColor];
refreshControl.tintColor = [UIColor whiteColor];
[refreshControl addTarget:self
action:@selector(getLatestData)
forControlEvents:UIControlEventValueChanged];
[yourTableviewName addSubview:refreshControl];
-(void)getLatestData
{
// here add your reload method
[self XXXXX];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
forKey:NSForegroundColorAttributeName];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
refreshControl.attributedTitle = attributedTitle;
[refreshControl endRefreshing];
}
第二种方法与我在中建议的代码几乎相同,因此我认为您的错误在tableViewController中。它被保留了吗?In.h
@property(nonatomic,strong) UIRefreshControl *refreshControl;
In.m
- (void)viewDidLoad {
[super viewDidLoad];
//Initialize the refresh control
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshBrandList:) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:self.refreshControl];
}
-(void) refreshBrandList:(id)sender{
[self ServiceCall];
[self.refreshControl endRefreshing];
}
SVPullToRefresh+SVInfinitiesScrolling
- 易于使用
- 提供上下拉以刷新
@选择器本身没有被调用,当我向下拖动tableview时,我找不到活动指示器tableview约束问题是否会影响refreshcontrol??我不确定,但我认为代码的问题在于UITableViewController没有被保留(我可以看到);其他变量都没有引用它。如果UITableViewController通过ARC发布,
tableViewController.refreshControl=self.refreshControl代码>不会做任何事情。我的猜测是,如果将tableViewController作为强属性添加到对象,这段代码应该可以工作。请查看我的答案。我已经在使用这段代码了。请建议其他一些不同的答案。问题是,您的选择器没有工作,或者您没有看到刷新图标。我看不到刷新图标和@selector工作。使用这段代码,我们可以将刷新图标的框架更新得更低一点吗,我发现刷新图标位于最顶端,因此它不完全可见。是的,您可以。您需要在SvPullToRefreshView类中编辑带有白色大号的UIActivityIndicatorView样式,并根据需要添加适当的着色颜色。