单击UIBarButtonItem重新加载RSSFeed

时间:2012-05-14 22:02:32

标签: objective-c ios uibarbuttonitem

我是iOS开发的新手,我没有太多的编程经验。我要么从RSS源重新加载UITableView,我遵循以下教程:RSS Tutorial

我似乎无法向其添加重新加载按钮,因为有时它无法第一次加载并且想要在顶部栏中添加一个按钮来重新加载数据。

就像我说的,我对Objective-C的经验几乎没有任何帮助,但任何帮助都会受到赞赏。

以下代码是刷新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];
}

1 个答案:

答案 0 :(得分:0)

在调用reloadClick操作时,您实际上并未从RSS源中获取数据。

您想要调用refresh方法,一旦您的ASIHTTP请求全部完成,您想要致电[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];
}