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
I don't see it in the viewWillAppear:animated code you posted.  Did you just omit it?  It should work fine there but it's probably more appropriate to put it in the setter of the table view data source.

On Jan 31, 2012, at 7:14 PM, Ray Zhang wrote:

This is exactly what I want to ask where I should to the 'reloadData'? Cause currently I does the reloadData at (void)viewWillAppear:(BOOL)animated, which only works when the table first loaded. 


On Feb 1, 2012, at 11:06 AM, James Massara wrote:

Does your setter for recentlyViewPhotos do a 'reloadData' on the tableView?

On Jan 31, 2012, at 6:50 PM, Ray Zhang wrote:

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.



--
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.


--
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