【问题标题】:LazyTableImages for iPhone Sample Code Reload QuestionLazyTableImages for iPhone 示例代码重新加载问题
【发布时间】:2010-11-18 23:23:25
【问题描述】:

我正在使用 LazyTableImages 示例代码从 RSS 提要异步加载表格视图中的图像。我想知道的是,添加新项目后如何在此表中重新加载(重新启动解析操作),具体到此示例?

http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

非常感谢。

【问题讨论】:

    标签: iphone xcode


    【解决方案1】:

    我认为您需要重新请求下载。您可能希望向 LazyTableAppDelegate 添加一个新方法来执行此操作,因为这是执行初始下载的类:

    - (void)reloadAppList
    {
        NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:TopPaidAppsFeed]];
        self.appListFeedConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];
    }
    

    另外,修改-[LazyTableAppDelegate handleLoadedApps:] 清除旧数据,如下:

    - (void)handleLoadedApps:(NSArray *)loadedApps
    {
        [self.appRecords removeAllObjects];
        rootViewController.entries = [NSArray array];
        [self.appRecords addObjectsFromArray:loadedApps];
    
        // tell our table view to reload its data, now that parsing has completed
        [rootViewController.tableView reloadData];
    }
    

    我自己没有尝试过,但这是基本的想法。

    【讨论】:

    • 嗨瑞恩,感谢您的回复。我已经尝试过了,我理解这是主要思想,但它崩溃了,加上修改 handleLoadedApps 以清除对象会阻止 RSS 提要最初加载。任何进一步的指导将不胜感激。
    • handleLoadedApps 中将rootViewController.entries = [NSArray array]; 更改为[rootViewController.imageDownloadsInProgress removeAllObjects]; 似乎对我有用。就我而言,我在ApplicationWillEnterForeground 中创建了一个新的NSURLConnection
    【解决方案2】:

    (找不到评论的方法...)

    我在这里遇到了同样的问题并尝试了这种方法。使用 removeAllObjects 清除了 appRecords,但第二次,所有文章都适用,但图标没有加载。

    您可以通过这种方式更改原始示例代码来重现该问题:

    - (void)applicationDidFinishLaunching:(UIApplication *)application
    

    { // 配置并显示窗口 [窗口 addSubview:[self.navigationController 视图]]; [窗口 makeKeyAndVisible];

    // Initialize the array of app records and pass a reference to that list to our root view controller
    self.appRecords = [NSMutableArray array];
    rootViewController.entries = self.appRecords;
    

    // NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:TopPaidAppsFeed]]; //self.appListFeedConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];

    // Test the validity of the connection object. The most likely reason for the connection object
    // to be nil is a malformed URL, which is a programmatic error easily detected during development
    // If the URL is more dynamic, then you should implement a more flexible validation technique, and
    // be able to both recover from errors and communicate problems to the user in an unobtrusive manner.
    //
    //NSAssert(self.appListFeedConnection != nil, @"Failure to create URL connection.");
    
    // show in the status bar that network activity is starting
    // [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [self reloadData];
    

    }

    • (IBAction)重新加载:(id)发件人{ [自我重载数据]; }

    -(void)reloadData { NSLog(@"更新条目"); [self.appRecords removeAllObjects]; //[[myTableViewController imageDownloadsInProgress] removeAllObjects];

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:TopPaidAppsFeed]];
    self.appListFeedConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];
    
    // Test the validity of the connection object. The most likely reason for the connection object
    // to be nil is a malformed URL, which is a programmatic error easily detected during development
    // If the URL is more dynamic, then you should implement a more flexible validation technique, and
    // be able to both recover from errors and communicate problems to the user in an unobtrusive manner.
    //
    NSAssert(self.appListFeedConnection != nil, @"Failure to create URL connection.");
    
    // show in the status bar that network activity is starting
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      相关资源
      最近更新 更多