Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make example compile and run on iOS 5.x #14

Open
wants to merge 1 commit into from

2 participants

@chrisballinger

I made the example compile for iOS 5.x but there are some horrible problems with it (it springs back to the top when you try to scroll down).

@carsonb
Owner

Hi there,

Thanks for this! We've been using it in an internal project, and over the course of the few months, the API has really changed. See some of my comments in-line.

@carsonb carsonb commented on the diff
PSCollectionView.m
((6 lines not shown))
*stop = YES;
}
}];
}];
PSCollectionViewCell *cell = selectedCell.visibleCell;
- if (cell) {
+ if (cell && [self.collectionViewDelegate respondsToSelector:@selector(collectionView:didSelectView:atIndexPath:)]) {
@carsonb Owner
carsonb added a note

Excellent catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@carsonb carsonb commented on the diff
PSCollectionView.m
@@ -826,14 +826,14 @@ - (void)didSelectView:(UITapGestureRecognizer *)gestureRecognizer
[sectionItems enumerateObjectsUsingBlock:^(PSCollectionViewItemLayoutAttributes *candidate, NSUInteger idx, BOOL *stop) {
if (candidate.valid && CGRectContainsPoint(candidate.frame, tapPoint)) {
selectedCell = candidate;
- selectedIndexPath = [NSIndexPath indexPathForItem:idx inSection:[sectionNumber integerValue]];
+ selectedIndexPath = [NSIndexPath indexPathForRow:idx inSection:[sectionNumber integerValue]];
@carsonb Owner
carsonb added a note

indexPathForRow:inSection doesn't quite make sense due to there being multiple items horizontally (in one "row"). We use indexPathForItem:inSection: to conform similarly to how UICollectionView does. The PSViewController in the BroBoard example seems to still use the row property, when really it should be using the item property instead. See: http://developer.apple.com/library/ios/#documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/Reference.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 19, 2013
  1. @chrisballinger
This page is out of date. Refresh to see the latest.
View
27 BroBoard/BroBoard.xcodeproj/project.pbxproj
@@ -19,6 +19,10 @@
28C66827156F3E84008E82CF /* PSCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 28C66824156F3E84008E82CF /* PSCollectionView.m */; };
28C66828156F3E84008E82CF /* PSCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 28C66826156F3E84008E82CF /* PSCollectionViewCell.m */; };
28C6682C156F4073008E82CF /* PSBroView.m in Sources */ = {isa = PBXBuildFile; fileRef = 28C6682B156F4073008E82CF /* PSBroView.m */; };
+ D9DDFAE816AB2C5500350F2B /* PSCollectionViewItemLayoutAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = D9DDFAE316AB2C5500350F2B /* PSCollectionViewItemLayoutAttributes.m */; };
+ D9DDFAE916AB2C5500350F2B /* PSCollectionViewLayoutAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = D9DDFAE516AB2C5500350F2B /* PSCollectionViewLayoutAttributes.m */; };
+ D9DDFAEA16AB2C5500350F2B /* PSCollectionViewSectionViewLayoutAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = D9DDFAE716AB2C5500350F2B /* PSCollectionViewSectionViewLayoutAttributes.m */; };
+ D9DDFAEC16AB2C6000350F2B /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D9DDFAEB16AB2C6000350F2B /* Default-568h@2x.png */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -42,6 +46,13 @@
28C66826156F3E84008E82CF /* PSCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PSCollectionViewCell.m; path = ../PSCollectionViewCell.m; sourceTree = "<group>"; };
28C6682A156F4073008E82CF /* PSBroView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PSBroView.h; sourceTree = "<group>"; };
28C6682B156F4073008E82CF /* PSBroView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PSBroView.m; sourceTree = "<group>"; };
+ D9DDFAE216AB2C5500350F2B /* PSCollectionViewItemLayoutAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PSCollectionViewItemLayoutAttributes.h; path = ../PSCollectionViewItemLayoutAttributes.h; sourceTree = "<group>"; };
+ D9DDFAE316AB2C5500350F2B /* PSCollectionViewItemLayoutAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PSCollectionViewItemLayoutAttributes.m; path = ../PSCollectionViewItemLayoutAttributes.m; sourceTree = "<group>"; };
+ D9DDFAE416AB2C5500350F2B /* PSCollectionViewLayoutAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PSCollectionViewLayoutAttributes.h; path = ../PSCollectionViewLayoutAttributes.h; sourceTree = "<group>"; };
+ D9DDFAE516AB2C5500350F2B /* PSCollectionViewLayoutAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PSCollectionViewLayoutAttributes.m; path = ../PSCollectionViewLayoutAttributes.m; sourceTree = "<group>"; };
+ D9DDFAE616AB2C5500350F2B /* PSCollectionViewSectionViewLayoutAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PSCollectionViewSectionViewLayoutAttributes.h; path = ../PSCollectionViewSectionViewLayoutAttributes.h; sourceTree = "<group>"; };
+ D9DDFAE716AB2C5500350F2B /* PSCollectionViewSectionViewLayoutAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PSCollectionViewSectionViewLayoutAttributes.m; path = ../PSCollectionViewSectionViewLayoutAttributes.m; sourceTree = "<group>"; };
+ D9DDFAEB16AB2C6000350F2B /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -61,6 +72,7 @@
28C667F4156F3E60008E82CF = {
isa = PBXGroup;
children = (
+ D9DDFAEB16AB2C6000350F2B /* Default-568h@2x.png */,
28C66829156F3E88008E82CF /* PSCollectionView */,
28C66809156F3E60008E82CF /* BroBoard */,
28C66802156F3E60008E82CF /* Frameworks */,
@@ -116,6 +128,12 @@
28C66829156F3E88008E82CF /* PSCollectionView */ = {
isa = PBXGroup;
children = (
+ D9DDFAE216AB2C5500350F2B /* PSCollectionViewItemLayoutAttributes.h */,
+ D9DDFAE316AB2C5500350F2B /* PSCollectionViewItemLayoutAttributes.m */,
+ D9DDFAE416AB2C5500350F2B /* PSCollectionViewLayoutAttributes.h */,
+ D9DDFAE516AB2C5500350F2B /* PSCollectionViewLayoutAttributes.m */,
+ D9DDFAE616AB2C5500350F2B /* PSCollectionViewSectionViewLayoutAttributes.h */,
+ D9DDFAE716AB2C5500350F2B /* PSCollectionViewSectionViewLayoutAttributes.m */,
28C66823156F3E84008E82CF /* PSCollectionView.h */,
28C66824156F3E84008E82CF /* PSCollectionView.m */,
28C66825156F3E84008E82CF /* PSCollectionViewCell.h */,
@@ -178,6 +196,7 @@
28C6680E156F3E60008E82CF /* InfoPlist.strings in Resources */,
28C6681A156F3E60008E82CF /* PSViewController_iPhone.xib in Resources */,
28C6681D156F3E60008E82CF /* PSViewController_iPad.xib in Resources */,
+ D9DDFAEC16AB2C6000350F2B /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -194,6 +213,9 @@
28C66827156F3E84008E82CF /* PSCollectionView.m in Sources */,
28C66828156F3E84008E82CF /* PSCollectionViewCell.m in Sources */,
28C6682C156F4073008E82CF /* PSBroView.m in Sources */,
+ D9DDFAE816AB2C5500350F2B /* PSCollectionViewItemLayoutAttributes.m in Sources */,
+ D9DDFAE916AB2C5500350F2B /* PSCollectionViewLayoutAttributes.m in Sources */,
+ D9DDFAEA16AB2C5500350F2B /* PSCollectionViewSectionViewLayoutAttributes.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -232,6 +254,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -257,6 +280,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -278,6 +302,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BroBoard/BroBoard-Prefix.pch";
INFOPLIST_FILE = "BroBoard/BroBoard-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -289,6 +314,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BroBoard/BroBoard-Prefix.pch";
INFOPLIST_FILE = "BroBoard/BroBoard-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -313,6 +339,7 @@
28C66822156F3E60008E82CF /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
View
13 BroBoard/BroBoard/PSAppDelegate.m
@@ -15,21 +15,14 @@ @implementation PSAppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
-- (void)dealloc
-{
- [_window release];
- [_viewController release];
- [super dealloc];
-}
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- self.viewController = [[[PSViewController alloc] initWithNibName:@"PSViewController_iPhone" bundle:nil] autorelease];
+ self.viewController = [[PSViewController alloc] initWithNibName:@"PSViewController_iPhone" bundle:nil];
} else {
- self.viewController = [[[PSViewController alloc] initWithNibName:@"PSViewController_iPad" bundle:nil] autorelease];
+ self.viewController = [[PSViewController alloc] initWithNibName:@"PSViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
View
5 BroBoard/BroBoard/PSBroView.m
@@ -32,11 +32,11 @@ - (id)initWithFrame:(CGRect)frame {
if (self) {
self.backgroundColor = [UIColor whiteColor];
- self.imageView = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
+ self.imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
self.imageView.clipsToBounds = YES;
[self addSubview:self.imageView];
- self.captionLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
+ self.captionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.captionLabel.font = [UIFont boldSystemFontOfSize:14.0];
self.captionLabel.numberOfLines = 0;
[self addSubview:self.captionLabel];
@@ -53,7 +53,6 @@ - (void)prepareForReuse {
- (void)dealloc {
self.imageView = nil;
self.captionLabel = nil;
- [super dealloc];
}
- (void)layoutSubviews {
View
24 BroBoard/BroBoard/PSViewController.m
@@ -63,9 +63,7 @@ - (void)dealloc {
self.collectionView.collectionViewDataSource = nil;
self.collectionView = nil;
- self.items = nil;
-
- [super dealloc];
+ self.items = nil;
}
- (void)viewDidLoad {
@@ -110,7 +108,7 @@ - (void)loadDataSource {
if (!error && responseCode == 200) {
id res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if (res && [res isKindOfClass:[NSDictionary class]]) {
- self.items = [res objectForKey:@"gallery"];
+ self.items = [res objectForKey:@"data"];
[self dataSourceDidLoad];
} else {
[self dataSourceDidError];
@@ -130,14 +128,20 @@ - (void)dataSourceDidError {
}
#pragma mark - PSCollectionViewDelegate and DataSource
-- (NSInteger)numberOfViewsInCollectionView:(PSCollectionView *)collectionView {
+
+- (NSUInteger) numberOfSectionsInCollectionView:(PSCollectionView *)collectionView {
+ return 1;
+}
+
+- (NSUInteger) collectionView:(PSCollectionView *)collectionView numberOfViewsInSection:(NSUInteger)section {
return [self.items count];
}
-- (PSCollectionViewCell *)collectionView:(PSCollectionView *)collectionView viewAtIndex:(NSInteger)index {
- NSDictionary *item = [self.items objectAtIndex:index];
+- (PSCollectionViewCell *)collectionView:(PSCollectionView *)collectionView viewAtIndexPath:(NSIndexPath *)indexPath {
+ static NSString *viewIdentifier = @"ViewIdentifier";
+ NSDictionary *item = [self.items objectAtIndex:indexPath.row];
- PSBroView *v = (PSBroView *)[self.collectionView dequeueReusableView];
+ PSBroView *v = (PSBroView *)[self.collectionView dequeueReusableViewWithIdentifier:viewIdentifier];
if (!v) {
v = [[PSBroView alloc] initWithFrame:CGRectZero];
}
@@ -147,8 +151,8 @@ - (PSCollectionViewCell *)collectionView:(PSCollectionView *)collectionView view
return v;
}
-- (CGFloat)heightForViewAtIndex:(NSInteger)index {
- NSDictionary *item = [self.items objectAtIndex:index];
+- (CGFloat)collectionView:(PSCollectionView *)collectionView heightForViewAtIndexPath:(NSIndexPath *)indexPath {
+ NSDictionary *item = [self.items objectAtIndex:indexPath.row];
return [PSBroView heightForViewWithObject:item inColumnWidth:self.collectionView.colWidth];
}
View
BIN  BroBoard/Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
10 PSCollectionView.m
@@ -453,8 +453,8 @@ - (void)performLayout
NSMutableArray *sectionItems = _sectionItems[sectionNumber];
[sectionItems enumerateObjectsUsingBlock:^(PSCollectionViewItemLayoutAttributes *itemAttributes, NSUInteger idx, BOOL *stop) {
if (itemAttributes.valid == NO) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForItem:idx inSection:section];
-
+ NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:section];
+
//ensure we have the height for this item
CGFloat height = itemAttributes.frame.size.height;
if (height == 0.0f) {
@@ -500,7 +500,7 @@ - (void)performLayout
itemAttributes.visibleCell = nil;
} else if (visibleCell && itemAttributes.visibleCell == nil) {
//Cell is now visible, add it in
- NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:[sectionNumber integerValue]];
+ NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:[sectionNumber integerValue]];
PSCollectionViewCell *newCell = [self.collectionViewDataSource collectionView:self viewAtIndexPath:indexPath];
itemAttributes.visibleCell = newCell;
[self addSubview:newCell];
@@ -826,14 +826,14 @@ - (void)didSelectView:(UITapGestureRecognizer *)gestureRecognizer
[sectionItems enumerateObjectsUsingBlock:^(PSCollectionViewItemLayoutAttributes *candidate, NSUInteger idx, BOOL *stop) {
if (candidate.valid && CGRectContainsPoint(candidate.frame, tapPoint)) {
selectedCell = candidate;
- selectedIndexPath = [NSIndexPath indexPathForItem:idx inSection:[sectionNumber integerValue]];
+ selectedIndexPath = [NSIndexPath indexPathForRow:idx inSection:[sectionNumber integerValue]];
@carsonb Owner
carsonb added a note

indexPathForRow:inSection doesn't quite make sense due to there being multiple items horizontally (in one "row"). We use indexPathForItem:inSection: to conform similarly to how UICollectionView does. The PSViewController in the BroBoard example seems to still use the row property, when really it should be using the item property instead. See: http://developer.apple.com/library/ios/#documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/Reference.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
*stop = YES;
}
}];
}];
PSCollectionViewCell *cell = selectedCell.visibleCell;
- if (cell) {
+ if (cell && [self.collectionViewDelegate respondsToSelector:@selector(collectionView:didSelectView:atIndexPath:)]) {
@carsonb Owner
carsonb added a note

Excellent catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
[self.collectionViewDelegate collectionView:self didSelectView:cell atIndexPath:selectedIndexPath];
}
}
Something went wrong with that request. Please try again.