Permalink
Browse files

initializing

  • Loading branch information...
0 parents commit d7d7a69675c41f1a4e48decfe57ef992dd11d6ad sjbyrd committed Jul 18, 2011
Showing with 560 additions and 0 deletions.
  1. +28 −0 CustomCell.h
  2. +119 −0 CustomCell.m
  3. +1 −0 README.txt
  4. +19 −0 TableDataSource.h
  5. +393 −0 TableDataSource.m
  6. 0 TableDataSource.txt
@@ -0,0 +1,28 @@
+#import <UIKit/UIKit.h>
+
+typedef void (^ButtonPressBlock)();
+
+@interface CustomCell : UITableViewCell
+{
+ UIButton* fromCurrentBtn;
+ UIButton* fromPreviousBtn;
+ UIView* defaultView;
+ UILabel* defaultLabel;
+
+ ButtonPressBlock currentButtonPressed;
+ ButtonPressBlock previousButtonPressed;
+}
+@property (nonatomic,retain) UIButton* fromCurrentBtn;
+@property (nonatomic,retain) UIButton* fromPreviousBtn;
+@property (nonatomic,retain) UIView* defaultView;
+@property (nonatomic,retain) UILabel* defaultLabel;
+
+@property (copy) ButtonPressBlock currentButtonPressed;
+@property (copy) ButtonPressBlock previousButtonPressed;
+
+
+- (void)setText:(NSString*)text;
+- (void)currentButtonFunction:(id)sender;
+- (void)previousButtonFunction:(id)sender;
+
+@end
@@ -0,0 +1,119 @@
+#import "CustomCell.h"
+
+
+@implementation CustomCell
+
+@synthesize fromCurrentBtn;
+@synthesize fromPreviousBtn;
+@synthesize defaultView;
+@synthesize defaultLabel;
+@synthesize currentButtonPressed;
+@synthesize previousButtonPressed;
+
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+{
+ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
+
+ if (self)
+ {
+ if ([reuseIdentifier isEqualToString:@"short"])
+ {
+ self.defaultView = [[[UIView alloc] initWithFrame:CGRectMake(self.contentView.frame.origin.x,
+ self.contentView.frame.origin.y,
+ self.contentView.frame.size.width,
+ self.contentView.frame.size.height)]
+ autorelease];
+ }
+ else
+ {
+ [self.contentView setFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height * 2)];
+
+ self.defaultView = [[[UIView alloc] initWithFrame:CGRectMake(self.contentView.frame.origin.x,
+ self.contentView.frame.origin.y,
+ self.contentView.frame.size.width,
+ self.contentView.frame.size.height)]
+ autorelease];
+
+ //Buttons
+ self.fromCurrentBtn = [[UIButton buttonWithType:UIButtonTypeCustom] autorelease];
+ self.fromPreviousBtn = [[UIButton buttonWithType:UIButtonTypeCustom] autorelease];
+
+ UIImage* currentBtnImage = [UIImage imageNamed:@"fromCurrentBtn.png"];
+ [self.fromCurrentBtn setBackgroundImage:currentBtnImage forState:UIControlStateNormal];
+
+ UIImage* previousBtnImage = [UIImage imageNamed:@"fromPreviousBtn.png"];
+ [self.fromPreviousBtn setBackgroundImage:previousBtnImage forState:UIControlStateNormal];
+
+ self.fromCurrentBtn.titleLabel.text = @"current";
+ self.fromPreviousBtn.titleLabel.text = @"previous";
+ self.fromCurrentBtn.frame = CGRectMake(7, 48, 151, 31);
+ self.fromPreviousBtn.frame = CGRectMake(163, 48, 151, 31);
+
+ [self.fromCurrentBtn addTarget:self action:@selector(currentButtonFunction:) forControlEvents:UIControlEventTouchUpInside];
+ [self.fromPreviousBtn addTarget:self action:@selector(previousButtonFunction:) forControlEvents:UIControlEventTouchUpInside];
+
+ UIImage* bgImg = [UIImage imageNamed:@"routeBackground.png"];
+ UIImageView* backgroundImage = [[[UIImageView alloc] initWithImage:bgImg] autorelease];
+ [backgroundImage setFrame:CGRectMake(0,44,320,44)];
+
+ [self.defaultView addSubview:backgroundImage];
+ [self.defaultView addSubview:fromCurrentBtn];
+ [self.defaultView addSubview:fromPreviousBtn];
+ }
+
+
+ //Labels
+ self.defaultLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 5, 310, 34)] autorelease];
+ self.defaultLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0];
+
+ [self.defaultView addSubview:defaultLabel];
+
+
+ [self.contentView addSubview:defaultView];
+ [self.contentView bringSubviewToFront:defaultView];
+
+ [self.contentView setClipsToBounds:YES];
+ }
+
+ return self;
+}
+
+
+
+- (void)setText:(NSString*)text
+{
+ self.defaultLabel.text = text;
+}
+
+
+- (void)currentButtonFunction:(id)sender
+{
+ currentButtonPressed();
+}
+
+- (void)previousButtonFunction:(id)sender
+{
+ previousButtonPressed();
+}
+
+
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated
+{
+ [super setSelected:selected animated:animated];
+}
+
+- (void)dealloc
+{
+ [defaultLabel release];
+ [fromCurrentBtn release];
+ [fromPreviousBtn release];
+ [defaultView release];
+ [currentButtonPressed release];
+ [previousButtonPressed release];
+
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1 @@
+These four files contain the bare skeletal outline for how I accomplished a custom UITableViewCell that would expand when selected to reveal two buttons, each with a function unique to the cell. This code has been adapted from a previous project and *has not been tested*. I have uploaded it merely as a reference, since code for dynamically expanding cell views seems to be very sought-after on StackOverflow
@@ -0,0 +1,19 @@
+
+#import <UIKit/UIKit.h>
+
+@interface TableDataSource : UIViewController <UITableViewDelegate, UITableViewDataSource>
+{
+ NSMutableArray* dataSource; //array of NSDictionaries, each of which represents a location on a route
+ UITableView* table;
+ UIBarButtonItem* editBtn;
+}
+
+@property (nonatomic, retain) Route* currentRoute;
+@property (nonatomic, retain) IBOutlet UITableView* table;
+@property (nonatomic, retain) IBOutlet UIBarButtonItem* editBtn;
+
+- (IBAction)toggleEditTable;
+
+- (void)clearOldPath;
+
+@end
Oops, something went wrong.

0 comments on commit d7d7a69

Please sign in to comment.