Git Product home page Git Product logo

pscollectionview's Introduction

What is PSCollectionView?

It's a Pinterest style scroll view designed to be used similar to a UITableView.

It supports Portrait and Landscape orientations.

I built this as a hack to show my friends. Any suggestions or improvements are very welcome!

Coming soon... A fully functional demo app.

What is PSCollectionViewCell?

It's the equivalent of UITableViewCell

It implements base methods for configuring data and calculating height

Note: You should subclass this!

Want to see this code in a live app?

I use this in my iPhone/iPad app, Lunchbox.

Screenshot

ARC

Fully ARC compatible now

How to use:

Here's an example of creating an instance of PSCollectionView

self.collectionView = [[PSCollectionView alloc] initWithFrame:CGRectZero];
self.collectionView.delegate = self; // This is for UIScrollViewDelegate
self.collectionView.collectionViewDelegate = self;
self.collectionView.collectionViewDataSource = self;
self.collectionView.backgroundColor = [UIColor clearColor];
self.collectionView.autoresizingMask = ~UIViewAutoresizingNone;

Setting number of columns

// Specify number of columns for both iPhone and iPad
if (isDeviceIPad()) {
    self.collectionView.numColsPortrait = 3;
    self.collectionView.numColsLandscape = 4;
} else {
    self.collectionView.numColsPortrait = 1;
    self.collectionView.numColsLandscape = 2;
}

Add a header view

UIView *headerView = ...
self.collectionView.headerView = headerView;

Add a footer view

UIView *footerView = ...
self.collectionView.footerView = footerView;

Reloading Data [self.collectionView reloadData];

Delegate and DataSource

- (Class)collectionView:(PSCollectionView *)collectionView cellClassForRowAtIndex:(NSInteger)index {
    return [PSCollectionViewCell class];
}

- (NSInteger)numberOfRowsInCollectionView:(PSCollectionView *)collectionView {
    return 0;
}

- (UIView *)collectionView:(PSCollectionView *)collectionView cellForRowAtIndex:(NSInteger)index {
    return nil;
}

- (CGFloat)collectionView:(PSCollectionView *)collectionView heightForRowAtIndex:(NSInteger)index {
    return 0.0;
}

License

Copyright (c) 2012 Peter Stone (https://www.impeterstone.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Questions?

Feel free to send me an email if you have any questions implementing PSCollectionView!

pscollectionview's People

Contributors

ptshih avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pscollectionview's Issues

How would i make this work in PSCollectionView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return tweets.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TweetCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
NSString *text = [tweet objectForKey:@"text"];
NSString *name = [[tweet objectForKey:@"user"] objectForKey:@"name"];

cell.textLabel.text = text;
cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name];

return cell;
}

P.S. When is the example/demo app coming out!

can't support to ios4

when I run in simulator of ios4, it terminated with the error as below:

sendAsynchronousRequest:queue:completionHandler:]: unrecognized selector sent to class 0x967f18
2012-07-26 17:01:19.419 BroBoard[6282:b903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]: unrecognized selector sent to class 0x967f18'

pod

could you plz make it pod

How to add a UILabel in PSCollectionViewCell ?

Hi , there

Thanks so much for letting me know about this fantastic component "PSCollectionView".
I am getting troubles to add a label in PSCollectionViewCell.
How can I add this ?

Many thanks in advice..

Song.

What if the cell is UIWebView?

After UIWebView finished loading, it will called webViewDidFinishLoad and heightForViewWithObject need to recalculate again and maybe numberOfViewsInCollectionView need to be called again?

i got signal sigabrt

this line;
-[NSNull sizeWithFont:constrainedToSize:lineBreakMode:]:

lldb output:

2012-07-14 10:08:47.278 BroBoard[8913:f803] -[NSNull sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector sent to instance 0x146cce8
2012-07-14 10:08:47.279 BroBoard[8913:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector sent to instance 0x146cce8'
*** First throw call stack:
(0x13d6022 0x1567cd6 0x13d7cbd 0x133ced0 0x133ccb2 0x9340 0x4111 0x5ba2 0x51cd 0x3e85 0x3d6c 0xa2155e 0x95e63e 0x9571e7 0x956eea 0x9e70ad 0x3d9c330 0x3d9e509 0x130d803 0x130cd84 0x130cc9b 0x12bf7d8 0x12bf88a 0x20626 0x2b22 0x2a95)
terminate called throwing an exception(lldb)

maybe something wrong with the label size.

Please add semantic version tags

I’ve recently added PSCollectionView to the CocoaPods package manager repo.

CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.

However, PSCollectionView doesn't have any version tags. I’ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.

Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.

In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:

$ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags

when has headerView, some cell can`not selected

i add a header for PSCollectionView, and cause a bug, the index 2 (sometimes other) cell have no selected event dispatch. i debug it, and found that it cause by the NSStringFromCGRect and CGRectFromString, the two method "not completely interchangeable"
i fix the bug by create a new method instead of NSStringFromCGRect. and all is ok.

+(NSString *)toString:(CGRect)frame{
return [NSString stringWithFormat:@"{{%f, %f}, {%f, %f}}", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height];
}

just some questions

how can i add object with the exists items...

i mean i have NSMutable�Array for dataSource in page 1,

now i get page 2 data, i add the object to the items ,and use the reloadData method,and it don't work .

after reloadData,the view still display the old data (page 1),not the new data (page 1 + page 2).

somebody help me ??thanks ~!

Missing classes

Hi, in PSCollectionViewCell.h missing PSView
in PSCollectionView.m - UIView+PSKit.h

Can I get it somewhere?

Thanks

Flickers on reloadData and reuse identifier not present

Hi,
I found this written in your code.

/**
Stores a view for later reuse
TODO: add an identifier like UITableView
*/

  • (void)enqueueReusableView:(PSCollectionViewCell *)view;

In current code, this is not is taken care and its not using any identifier like UITableViewCell uses.
Can you please guide me so that i can do it, if nobody is doing it ?
Or if done can you point me to the correct code.

I don't exactly know how to add identifier and add code in -prepareForReuse() function.
The problem is, because of this i get a flicker while calling reloadData and it doesn't looks good.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.