Added Custom Cell

This commit is contained in:
Kyle Fang
2013-02-26 03:32:05 +08:00
parent 1b0324f501
commit ff906d953d
7 changed files with 204 additions and 22 deletions

View File

@@ -15,6 +15,7 @@
0486284C16B000D700F62384 /* Progress.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 0486284A16B000D700F62384 /* Progress.xcdatamodeld */; };
048D433D16DB9BA400A40CB1 /* Progress.nss in Resources */ = {isa = PBXBuildFile; fileRef = 048D433C16DB9BA400A40CB1 /* Progress.nss */; };
048D434016DB9D5400A40CB1 /* PPRemindersViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 048D433F16DB9D5400A40CB1 /* PPRemindersViewController.m */; };
048D437216DBC4E000A40CB1 /* ReminderItemCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 048D437116DBC4E000A40CB1 /* ReminderItemCell.m */; };
04BDDEC516902D0900D04A9E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04BDDEC416902D0900D04A9E /* UIKit.framework */; };
04BDDEC716902D0900D04A9E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04BDDEC616902D0900D04A9E /* Foundation.framework */; };
04BDDEC916902D0900D04A9E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04BDDEC816902D0900D04A9E /* CoreGraphics.framework */; };
@@ -58,6 +59,8 @@
048D433C16DB9BA400A40CB1 /* Progress.nss */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Progress.nss; sourceTree = "<group>"; };
048D433E16DB9D5300A40CB1 /* PPRemindersViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PPRemindersViewController.h; sourceTree = "<group>"; };
048D433F16DB9D5400A40CB1 /* PPRemindersViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PPRemindersViewController.m; sourceTree = "<group>"; };
048D437016DBC4E000A40CB1 /* ReminderItemCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReminderItemCell.h; sourceTree = "<group>"; };
048D437116DBC4E000A40CB1 /* ReminderItemCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReminderItemCell.m; sourceTree = "<group>"; };
04BDDEC016902D0900D04A9E /* Progress.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Progress.app; sourceTree = BUILT_PRODUCTS_DIR; };
04BDDEC416902D0900D04A9E /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
04BDDEC616902D0900D04A9E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -155,6 +158,8 @@
04BDDECA16902D0900D04A9E /* Progress */ = {
isa = PBXGroup;
children = (
048D437016DBC4E000A40CB1 /* ReminderItemCell.h */,
048D437116DBC4E000A40CB1 /* ReminderItemCell.m */,
048D433E16DB9D5300A40CB1 /* PPRemindersViewController.h */,
048D433F16DB9D5400A40CB1 /* PPRemindersViewController.m */,
04FD824516DB02910028AF2A /* GVUserDefaults+Progress.h */,
@@ -359,6 +364,7 @@
04FD824216DAFB770028AF2A /* PPEvenKitManager.m in Sources */,
04FD824716DB02910028AF2A /* GVUserDefaults+Progress.m in Sources */,
048D434016DB9D5400A40CB1 /* PPRemindersViewController.m in Sources */,
048D437216DBC4E000A40CB1 /* ReminderItemCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -24,4 +24,8 @@
- (void)getReminderItemsInListWithIdentifier:(NSString *)listIdentifier includeCompleted:(BOOL)includeCompleted includeImcompleted:(BOOL)incluImcomple withCompletionBlock:(void (^)(NSArray *reminedrItems))completion;
- (BOOL)saveReminder:(EKReminder *)reminder;
- (BOOL)deleteReminder:(EKReminder *)reminder;
@end

View File

@@ -92,7 +92,9 @@ static PPEvenKitManager *_sharedManager;
reminderPredicate = [self.defaultStore predicateForCompletedRemindersWithCompletionDateStarting:nil ending:nil calendars:@[calendar]];
}
[self.defaultStore fetchRemindersMatchingPredicate:reminderPredicate completion:^(NSArray *reminders) {
completion([reminders copy]);
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
completion([reminders copy]);
}];
}];
}
} else {
@@ -101,4 +103,12 @@ static PPEvenKitManager *_sharedManager;
}
- (BOOL)saveReminder:(EKReminder *)reminder{
return [self.defaultStore saveReminder:reminder commit:YES error:nil];
}
- (BOOL)deleteReminder:(EKReminder *)reminder{
return [self.defaultStore removeReminder:reminder commit:YES error:nil];
}
@end

View File

@@ -9,13 +9,16 @@
#import "PPRemindersViewController.h"
#import "PPEvenKitManager.h"
#import <SVProgressHUD/SVProgressHUD.h>
#import "ReminderItemCell.h"
@interface PPRemindersViewController ()
@interface PPRemindersViewController () <ReminderItemCellDelegate>
@property (nonatomic) NSArray *remindersDatasource;
@end
@implementation PPRemindersViewController
static NSString *CellIdentifier = @"ReminderCell";
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
@@ -32,19 +35,26 @@
self.clearsSelectionOnViewWillAppear = NO;
self.navigationController.navigationBarHidden = YES;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.tableView registerClass:[ReminderItemCell class] forCellReuseIdentifier:CellIdentifier];
[SVProgressHUD show];
NSString *defaultReminderIdentifier = [[PPEvenKitManager sharedManager] defaultReminderListIdentifier];
[[PPEvenKitManager sharedManager] getReminderItemsInListWithIdentifier:defaultReminderIdentifier includeCompleted:YES includeImcompleted:YES withCompletionBlock:^(NSArray *reminedrItems) {
self.remindersDatasource = reminedrItems;
[self.tableView reloadData];
[SVProgressHUD dismiss];
[self.tableView reloadData];
}];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
@@ -60,16 +70,24 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ReminderCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ReminderItemCell *cell = [[ReminderItemCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
EKReminder *reminder = [self.remindersDatasource objectAtIndex:indexPath.row];
cell.delegate = self;
cell.textLabel.text = reminder.title;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
cell.accessoryType = reminder.completed ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;
}
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
// return [[UIView alloc] init];
//}
//
//- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
// return 1;
//}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return [[UIView alloc] init];
}
@@ -130,4 +148,24 @@
*/
}
#pragma mark - ReminderCell Delegate
- (void)completedByTheUser:(ReminderItemCell *)sender{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
EKReminder *reminder = [self.remindersDatasource objectAtIndex:indexPath.row];
sender.accessoryType = reminder.completed ? UITableViewCellAccessoryNone : UITableViewCellAccessoryCheckmark;
reminder.completed = !reminder.completed;
[[PPEvenKitManager sharedManager] saveReminder:reminder];
}
- (void)deletedByTheUser:(ReminderItemCell *)sender{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
EKReminder *reminder = [self.remindersDatasource objectAtIndex:indexPath.row];
NSMutableArray *mutableDataSource = [self.remindersDatasource mutableCopy];
[mutableDataSource removeObjectAtIndex:indexPath.row];
self.remindersDatasource = mutableDataSource;
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[[PPEvenKitManager sharedManager] deleteReminder:reminder];
}
@end

View File

@@ -0,0 +1,22 @@
//
// ReminderItemCell.h
// Progress
//
// Created by Kyle Fang on 2/26/13.
// Copyright (c) 2013 kylefang. All rights reserved.
//
#import <UIKit/UIKit.h>
@class ReminderItemCell;
@protocol ReminderItemCellDelegate <NSObject>
- (void)deletedByTheUser:(ReminderItemCell *)sender;
- (void)completedByTheUser:(ReminderItemCell *)sender;
@end
@interface ReminderItemCell : UITableViewCell
@property (nonatomic) id <ReminderItemCellDelegate> delegate;
@end

105
Progress/ReminderItemCell.m Normal file
View File

@@ -0,0 +1,105 @@
//
// ReminderItemCell.m
// Progress
//
// Created by Kyle Fang on 2/26/13.
// Copyright (c) 2013 kylefang. All rights reserved.
//
#import "ReminderItemCell.h"
#define kDefaultEdageXOffset 80
@interface ReminderItemCell() <UIGestureRecognizerDelegate>
@property (nonatomic) CGPoint originalCenter;
@end
@implementation ReminderItemCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.textLabel.numberOfLines = 2;
self.textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
panGesture.delegate = self;
[self addGestureRecognizer:panGesture];
}
return self;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
if ([gestureRecognizer respondsToSelector:@selector(translationInView:)]) {
UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint translation = [panGesture translationInView:[self superview]];
return fabsf(translation.x) > fabsf(translation.y);
} else {
return YES;
}
}
- (void)panGestureHandler:(UIPanGestureRecognizer *)gesture{
CGRect checkMarkOriginFrame = CGRectMake(20, 20, 40, 40);
CGRect deleteMarkOriginFrame = CGRectMake(self.frame.size.width-20-40, 20, 40, 40);
if (gesture.state == UIGestureRecognizerStateBegan) {
self.originalCenter = self.center;
UIImageView *checkMarkView = [[UIImageView alloc] initWithFrame:checkMarkOriginFrame];
checkMarkView.backgroundColor = [UIColor greenColor];
checkMarkView.tag = 1;
UIImageView *deleteMarkView = [[UIImageView alloc] initWithFrame:deleteMarkOriginFrame];
deleteMarkView.backgroundColor = [UIColor redColor];
deleteMarkView.tag = 2;
[self insertSubview:checkMarkView atIndex:0];
[self insertSubview:deleteMarkView atIndex:0];
} else {
CGPoint translation = [gesture translationInView:self];
CGFloat xOffset = translation.x;
UIView *checkMarkView = [self viewWithTag:1];
UIView *deleteMarkView = [self viewWithTag:2];
if (gesture.state == UIGestureRecognizerStateChanged) {
self.center = CGPointMake(self.originalCenter.x+xOffset, self.originalCenter.y);
if (xOffset>-kDefaultEdageXOffset && xOffset<kDefaultEdageXOffset) {
checkMarkView.frame = CGRectOffset(checkMarkOriginFrame, -xOffset, 0);
deleteMarkView.frame = CGRectOffset(deleteMarkOriginFrame, -xOffset, 0);
}
} else if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateCancelled) {
[checkMarkView removeFromSuperview];
[deleteMarkView removeFromSuperview];
if (xOffset>kDefaultEdageXOffset) {
NSLog(@">kDefaultEdageXOffset");
[UIView animateWithDuration:0.2 animations:^{
self.frame = CGRectOffset(self.frame, -self.frame.origin.x, 0);
} completion:^(BOOL finished) {
[self.delegate completedByTheUser:self];
}];
} else if (xOffset<-kDefaultEdageXOffset) {
NSLog(@"<-kDefaultEdageXOffset");
[UIView animateWithDuration:0.2 animations:^{
self.frame = CGRectOffset(self.frame, self.frame.origin.x-self.frame.size.width, 0);
self.alpha = 0;
} completion:^(BOOL finished) {
[self.delegate deletedByTheUser:self];
}];
} else {
[UIView animateWithDuration:0.2 animations:^{
self.frame = CGRectOffset(self.frame, -self.frame.origin.x, 0);
}];
}
}
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end

View File

@@ -13,18 +13,23 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="ReminderCell" textLabel="Gi2-2j-rob" style="IBUITableViewCellStyleDefault" id="dwc-W6-Rod">
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="ReminderCell" textLabel="Gi2-2j-rob" detailTextLabel="nvd-Qt-JxD" style="IBUITableViewCellStyleValue1" id="dwc-W6-Rod" customClass="ReminderItemCell">
<rect key="frame" x="0.0" y="22" width="320" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="320" height="79"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="300" translatesAutoresizingMaskIntoConstraints="NO" id="Gi2-2j-rob">
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="a" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="10" translatesAutoresizingMaskIntoConstraints="NO" id="Gi2-2j-rob">
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</label>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nvd-Qt-JxD">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.2196078431372549" green="0.32941176470588235" blue="0.52941176470588236" alpha="1" colorSpace="calibratedRGB"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
@@ -82,14 +87,6 @@
<point key="canvasLocation" x="652" y="726"/>
</scene>
</scenes>
<classes>
<class className="NSLayoutConstraint" superclassName="NSObject">
<source key="sourceIdentifier" type="project" relativePath="./Classes/NSLayoutConstraint.h"/>
</class>
<class className="PPRemindersViewController" superclassName="UITableViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/PPRemindersViewController.h"/>
</class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>