1

请我想刷新我的表格的内容,但它不起作用。

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Last News";
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    //
    NSURL *url = [NSURL URLWithString:@"http://www.apinae.com/json.php"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];

    // test refresh
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    refreshControl.tintColor = [UIColormagentaColor];
    self.refreshControl = refreshControl;
    // test refresh

}

提前致谢。

4

1 回答 1

3

您没有为刷新控件设置操作。试试这个:

-(void) viewDidLoad
{
    [super viewDidLoad];
    UIRefreshControl *refreshControl = [UIRefreshControl new];
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to refresh..."];
    self.refreshControl = refreshControl;
}

- (void)refresh:(UIRefreshControl *)sender 
{
    // ... your refresh code
    NSURL *url = [NSURL URLWithString:@"http://www.apinae.com/json.php"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];

    [sender endRefreshing];
}

好吧,调用-endRefreshing应该在委托方法中,因此当文件下载并在表中刷新时它会停止刷新,但你明白了。

于 2013-05-19T13:10:56.653 回答