我知道它已經多次說明了這個問題,但似乎我無法找到解決方案與我的情況。我有一個應用程序在視圖控制器內有一個容器視圖控制器,它是一個表視圖控制器。在這個表格視圖中加載了一些rss提要。當我打開我的應用程序沒有互聯網連接時,我的數據沒有出現,但是當我將我的應用程序連接到互聯網後,我的桌子應該重新加載後,我拉下桌子,但它沒有。我嘗試了很多東西,但我找不到解決方案。我發佈我的代碼,如果有人可以幫助,我將不勝感激。謝謝。self.tableview重新加載後,應用程序連接到互聯網不工作
- (void)viewDidLoad {
[super viewDidLoad];
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@"http://url"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
self.tableView.dataSource = self;
self.tableView.delegate = self;
if (networkStatus == NotReachable)
{
number = 0;
}
else{
number = 1;
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
num = 5;
}
else{
num = feeds.count;
}}
這些都是我調用表主要方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return number;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(feeds.count > num){
return num + 1;
}
return num;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.userInteractionEnabled = YES;
// Set up the cell
[cell.textLabel setFont:[UIFont fontWithName:@"Verdana" size:15]];
[cell.textLabel setNumberOfLines:2];
[cell.detailTextLabel setFont:[UIFont fontWithName:@"Verdana" size:12]];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];
}
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"item"]) {
[item setObject:title forKey:@"title"];
[item setObject:link forKey:@"link"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:@"title"]) {
[title appendString:string];
} else if ([element isEqualToString:@"link"]) {
[link appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
這是我拉下來以後重裝我的數據
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGPoint targetPoint = *targetContentOffset;
CGPoint currentPoint = scrollView.contentOffset;
if (targetPoint.y > currentPoint.y) {
[self.tableView reloadData];
}}
是什麼觸發了從網絡到飼料數組的實際加載數據? – Paulw11 2014-12-03 21:54:32
這是一個RSS提要。但我在愛德華L的幫助下解決了這個問題。謝謝。 – user3882720 2014-12-03 22:17:55