Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

working example

  • Loading branch information...
commit 410466dc9a570264812f088d4275ef12be2f15cb 1 parent 22cf45b
@oscardelben authored
View
6 CellWithRightButton/CellWithRightButtonViewController.m
@@ -25,6 +25,10 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return 5;
}
+#define kRightButtonStateNormal 1
+#define kRightButtonStateSelected 2
+#define kRightButtonStateDone 3
+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
@@ -55,6 +59,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.buttonStateSelected = selectedButton;
cell.buttonStateDone = doneButton;
+ cell.rightButtonState = kRightButtonStateNormal;
+
cell.textLabel.text = [NSString stringWithFormat:@"Cell %i", indexPath.row];
return cell;
}
View
26 CellWithRightButton/CustomCell.m
@@ -9,11 +9,10 @@
#import "CustomCell.h"
#define padding 10
-#define fontSize 12
-#define kRightButtonStateNormal 0
-#define kRightButtonStateSelected 1
-#define kRightButtonStateDone 2
+#define kRightButtonStateNormal 1
+#define kRightButtonStateSelected 2
+#define kRightButtonStateDone 3
@implementation CustomCell
@@ -75,10 +74,7 @@ - (void)drawRect:(CGRect)rect
self.buttons = [NSArray arrayWithObjects:buttonStateNormal, buttonStateSelected, buttonStateDone, nil];
[self configureButtons:buttons];
-
- // Should set this if null (but we don't have null for integers right?). Maybe it's already 0 by default
- self.rightButtonState = kRightButtonStateNormal;
-
+
UIButton *button = (UIButton *)[buttons objectAtIndex:rightButtonState];
button.hidden = NO;
@@ -112,19 +108,9 @@ - (void)buttonTouched:(id)sender
// Cell was touched
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
- switch (rightButtonState)
+ if (rightButtonState == kRightButtonStateSelected)
{
- case kRightButtonStateNormal:
- // do nothing
- break;
-
- case kRightButtonStateDone:
- // do nothing
- break;
-
- case kRightButtonStateSelected:
- [self switchViewsFromState:kRightButtonStateSelected toState:kRightButtonStateNormal];
- break;
+ [self switchViewsFromState:kRightButtonStateSelected toState:kRightButtonStateNormal];
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.