Skip to content

Commit 3ca97ea

Browse files
committed
fixed some bugs
1 parent 4295e1b commit 3ca97ea

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

CustomCellSample/CustomCellSample/CustomCell.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated
132132
BOOL realSelected = !self.selected && selected;
133133
[super setSelected:realSelected animated:animated];
134134
self.baseView.selected = realSelected;
135+
[self.baseView setNeedsDisplay];
135136
}
136137

137138
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated

CustomCellSample/CustomCellSample/RootViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
NSIndexPath* openedIndexPath_;
1818
}
1919
@property (nonatomic, retain) IBOutlet FooterView* footerView;
20+
@property (nonatomic, retain) NSIndexPath* openedIndexPath;
2021

2122
// cell events
2223
- (IBAction)didTouchDoitButton:(id)sender event:(UIEvent*)event;

CustomCellSample/CustomCellSample/RootViewController.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
@implementation RootViewController
1616
@synthesize footerView;
17+
@synthesize openedIndexPath;
1718

1819
- (void)viewDidLoad
1920
{
@@ -48,7 +49,7 @@ - (void)viewWillAppear:(BOOL)animated
4849
{
4950
[super viewWillAppear:animated];
5051

51-
openedIndexPath_ = nil; // close all cells
52+
self.openedIndexPath = nil; // close all cells
5253
}
5354

5455
- (void)viewDidAppear:(BOOL)animated
@@ -103,12 +104,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
103104
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image%02ds.jpg", (r%8)+1]];
104105
// NSLog(@"%@", [NSString stringWithFormat:@"image%02ds.jpg", (r%8)+1]);
105106

106-
if ([openedIndexPath_ isEqual:indexPath]) {
107+
if ([self.openedIndexPath isEqual:indexPath]) {
107108
[cell setSlideOpened:YES animated:NO];
108-
[cell setSelected:YES animated:NO];
109109
} else {
110110
[cell setSlideOpened:NO animated:NO];
111-
[cell setSelected:NO animated:NO];
112111
}
113112

114113
return cell;
@@ -186,6 +185,7 @@ - (void)viewDidUnload
186185
- (void)dealloc
187186
{
188187
self.footerView = nil;
188+
self.openedIndexPath = nil;
189189
[super dealloc];
190190
}
191191

@@ -197,24 +197,24 @@ - (void)didSwipeCell:(UISwipeGestureRecognizer*)swipeRecognizer
197197
NSIndexPath* indexPath = [self.tableView indexPathForRowAtPoint:loc];
198198
CustomCell* cell = (CustomCell*)[self.tableView cellForRowAtIndexPath:indexPath];
199199

200-
if ([openedIndexPath_ isEqual:indexPath]) {
200+
if ([self.openedIndexPath isEqual:indexPath]) {
201201
if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
202202
// close cell
203203
[cell setSlideOpened:NO animated:YES];
204-
openedIndexPath_ = nil;
204+
self.openedIndexPath = nil;
205205
}
206206
} else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {
207-
if (openedIndexPath_) {
207+
if (self.openedIndexPath) {
208208
// close previous opened cell
209209
NSArray* visibleIndexPaths = [self.tableView indexPathsForVisibleRows];
210-
if ([visibleIndexPaths containsObject:openedIndexPath_]) {
211-
CustomCell* openedCell = (CustomCell*)[self.tableView cellForRowAtIndexPath:openedIndexPath_];
210+
if ([visibleIndexPaths containsObject:self.openedIndexPath]) {
211+
CustomCell* openedCell = (CustomCell*)[self.tableView cellForRowAtIndexPath:self.openedIndexPath];
212212
[openedCell setSlideOpened:NO animated:YES];
213213
}
214214
}
215215
// open new cell
216216
[cell setSlideOpened:YES animated:YES];
217-
openedIndexPath_ = indexPath;
217+
self.openedIndexPath = indexPath;
218218
}
219219

220220
}

0 commit comments

Comments
 (0)