Re: [iPhone-AppDev-Auditors] assignment 4, requirement 10: How to repopulate Recently Viewed Table Cell, when User views a new photo in Top Place Table?

Tuesday, January 31, 2012
Yes I did. The NSUserDefaults does get updated. The problem is the "Recently Viewed Table" does NOT get repopulated when User click on the "Recently Viewed Tab".

I should mention that "- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section" does NOT get called when User click on the "Recently Viewed Tab". 

For Reference: Following is the code to storing Recently Viewed Photo to NSUserDefaults:
 //Store Photo to NSUserDefaults, RecentlyViewedPhotoViewController will use it to display
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSMutableArray *photos = [[defaults objectForKey:RECENTILYVIEWEDPHOTOS_KEY] mutableCopy];
    if(!photos) photos = [NSMutableArray array];
    if ([photos indexOfObject:self.photo] == NSNotFound) {
        [photos addObject:self.photo];
        [defaults setObject:photos forKey:RECENTILYVIEWEDPHOTOS_KEY];
        if(![defaults synchronize]) NSLog(@"failed");   
    } 



On Feb 1, 2012, at 10:42 AM, James Massara wrote:

Hi zak, are you doing 'synchronize' after you update your NSUserDefaults object?

On Jan 31, 2012, at 6:34 PM, zak wrote:

How to repopulate Recently Viewed Table Cell, when User views a new
photo in Top Place Table?

Currently, I am setting my Recently Viewed Table Data Source in "-
(void)viewWillAppear:(BOOL)animated", which work for first time when
the application is launched. But it does NOT work when user views a
new photo at Top Place Tab.

I am getting the NSUserDefaults' Recently Viewed Photo List at
viewWillAppear. And I update NSUserDefaults at Top Place Tab.

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  self.recentlyViewedPhotos = [[NSUserDefaults standardUserDefaults]
objectForKey:RECENTILYVIEWEDPHOTOS_KEY];
}

--
You received this message because you are subscribed to the Google Groups "iPhone Application Development Auditors" group.
To post to this group, send email to iphone-appdev-auditors@googlegroups.com.
To unsubscribe from this group, send email to iphone-appdev-auditors+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphone-appdev-auditors?hl=en.


--
You received this message because you are subscribed to the Google Groups "iPhone Application Development Auditors" group.
To post to this group, send email to iphone-appdev-auditors@googlegroups.com.
To unsubscribe from this group, send email to iphone-appdev-auditors+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphone-appdev-auditors?hl=en.


0 comments:

Post a Comment