简体   繁体   English

单击UIBarButtonItem重新加载RSSFeed

[英]Reload a RSSFeed on clicking a UIBarButtonItem

I'm new to iOS development and I've not got much experience with programming. 我是iOS开发的新手,没有太多编程经验。 I either want to reload a UITableView from an RSS feed which I followed the following tutorial: RSS Tutorial 我要么想从我遵循以下教程的RSS feed中重新加载UITableView ,要么: RSS教程

I just can't seem to add a reload button to it as sometimes it fails to load first time and would like to add a button to the top bar the reload the data. 我只是似乎无法为其添加一个重新加载按钮,因为有时它第一次无法加载,并且想在顶部栏中添加一个按钮以重新加载数据。

Like I said I've got next to nothing in experience with Objective-C but any help would be appreciated. 就像我说的那样,我几乎没有Objective-C的经验,但是任何帮助将不胜感激。

The following code is part of the code that refreshes the feed: 以下代码是刷新Feed的代码的一部分:

- (void)viewDidLoad {
    [super viewDidLoad];    
    self.title = @"News";
    self.allEntries = [NSMutableArray array];
    self.queue = [[[NSOperationQueue alloc] init] autorelease];
    self.feeds = [NSArray arrayWithObjects:@"http://yourllanelli.org.uk/index.php?format=feed&type=atom",
        nil];    
    [self refresh];

    _reloadButton = [[[UIBarButtonItem alloc]
                                       initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered
                                       target:self action:@selector(reloadClick)]  autorelease];
}

-(void)reloadClick {    
    [UITableView refresh];
}

You are not actually getting the data from the RSS feed again when the reloadClick action is called. 当调用reloadClick动作时,您实际上并没有从RSS提要中再次获取数据。

You want to call your refresh method, and once your ASIHTTPRequests have all finished, you want to call [UITableView reloadData] 您想调用您的refresh方法,一旦您的ASIHTTPRequests全部完成,您就想调用[UITableView reloadData]

-(void)reloadClick
{    
    [self refresh];
}

- (void) requestDidFinish:(ASIHTTPRequest *)request {
     // you need to reload your UITableView once your ASIHTTPRequests finish.
     // since you are sending many requests to get the contents of different feeds, 
     // it would be better to call the following line only once, 
     // when all of the requests have finished
     [UITableView reloadData];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM