문제

Please I would like to refresh the contents of my table but it does not work.

- (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

}

Thanks in Advance.

도움이 되었습니까?

해결책

You didn't set the action for the refresh control. Try this instead:

-(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];
}

Well, the call to -endRefreshing should be in the delegate method so it stops refreshing when the file is downloaded and refreshed in the table, but you get the idea.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top