Get absolute position of a UITableViewCell

Here’s something that helped me when I was working with WEPopover to implement a popover in my iPhone app a la the iPad.

If your popover is being instantiated from a UIViewController with a UITableView in it that does not fill up the whole window, then you may have some issues getting the popover to align properly.

To get the alignment to work, you need to get the UITableViewCell‘s absolute position on screen.

You can achieve that through the following code:


CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];

And then…

[self.popoverController presentPopoverFromRect:rectInSuperview
inView:self.view
permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown|
UIPopoverArrowDirectionLeft|UIPopoverArrowDirectionRight)
animated:YES];

Thanks to Nick Weaver at this StackOverflow question for explaining this. Took some finding.

Get your Facebook Cover Photo using FQL

Facebook’s Graph API doesn’t have a method to easily retrieve a cover photo. However, provided that you (or a user) has given your app access to their Photo Albums, you can get the photo pretty easily.

The best way to get it through a single request is using the following FQL query.

SELECT cover_object_id from album where aid IN (SELECT aid, name FROM album WHERE owner=me() AND name="Cover Photos")

Note that you will need an access token to use this query. It definitely works for me, but I’m still testing with permissions to see what’s needed to make it work with other users. Will post an update if anything changes.

Update: Yep, this works. Have it running on my iPhone right now. Remember to change “me()” with the Facebook ID of the user. “me()” will only work from the FQL console.

Cool little Objective-C Method for grouping Facebook likes

Firstly, I just want to say I’m pretty proud of myself for writing compilable code at 4:30am. Go me.

I am making an iOS app as part of my 4th year design project, and we are leveraging Facebook for it. Basically, our app allows you to take a picture of someone’s face and we use facial recognition to pull up their Facebook profile.

Anyway, I was fooling around with the Facebook iOS SDK and one of the things I’ve been wanting to do is to group one’s likes by category. Facebook seems to just return a large array of likes, with no grouping. This little method below groups them so I can have a table view with headings like “Favorite Books”, “Favorite Movies”, etc. Check it out.