From 4a3f99a85a7d47a2b88521e89ce2a7f9a92da41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isaac=20Rodr=C3=ADguez?= Date: Thu, 21 Aug 2014 05:47:38 +0200 Subject: [PATCH 1/2] Update README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index e69de29..4c55295 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,30 @@ +IRImageTableView +================ +![](https://dl.dropboxusercontent.com/u/98803549/cm.png) + +A solution to add a UIImageView in an UITableView (inspired by Tweetbot). + +## IRImageTableView Class + +```objective-c +@interface IRImageTableView : UIViewController +@property (strong, nonatomic) NSArray *datao; +@property (nonatomic,retain) UITableView *tableView; +-(id) initWithTable:(UITableView*)table withData:(NSArray *)data; +@property (weak, nonatomic) id delegate; +@end + +``` + +##IRImageTableViewDelegate Protocol +```objective-c +@protocol IRImageTableViewDelegate +- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; +@end +``` + + +##Contact +- http://twitter.com/sideround +- hi@koideapps.com + From b54781380ea2d39ce0704bd4a46323cf5edae842 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Thu, 21 Aug 2014 16:08:25 +0200 Subject: [PATCH 2/2] Some changes --- IRImageTableView/IRImageTableView.h | 12 +++--- IRImageTableView/IRImageTableView.m | 66 +++++++++++++---------------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/IRImageTableView/IRImageTableView.h b/IRImageTableView/IRImageTableView.h index 09361b6..308e450 100644 --- a/IRImageTableView/IRImageTableView.h +++ b/IRImageTableView/IRImageTableView.h @@ -9,13 +9,15 @@ #import @protocol IRImageTableViewDelegate -- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; @end @interface IRImageTableView : UIViewController -@property (strong, nonatomic) NSArray *datao; -@property (nonatomic,retain) UITableView *tableView; --(id) initWithTable:(UITableView*)tabla withData:(NSArray *)data; -@property (weak, nonatomic) id delegate; +@property (nonatomic, strong) NSArray *data; +@property (nonatomic, strong) UITableView *tableView; +@property (nonatomic, weak) id delegate; + +- (id)initWithTable:(UITableView*)tabla withData:(NSArray *)data; + @end diff --git a/IRImageTableView/IRImageTableView.m b/IRImageTableView/IRImageTableView.m index 6ea6c37..c0a7da2 100644 --- a/IRImageTableView/IRImageTableView.m +++ b/IRImageTableView/IRImageTableView.m @@ -9,62 +9,59 @@ #import "IRImageTableView.h" #import "UIImageView+WebCache.h" -@interface IRImageTableView () - -@end @implementation IRImageTableView -@synthesize tableView,datao; -- (id)initWithTable:(UITableView *)tabla withData:(NSArray *)data{ - +- (id)initWithTable:(UITableView *)aTable withData:(NSArray *)aData +{ if (self = [super init]) { - tableView = tabla; - [tableView setDataSource:self]; - [tableView setDelegate:self]; - datao = data; + _data = aData; + _tableView = aTable; + [_tableView setDataSource:self]; + [_tableView setDelegate:self]; } return self; } #pragma mark UITableViewDataSource --(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [self.datao count]; + return [_data count]; } --(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 40; } --(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - NSDictionary *data = [self.datao objectAtIndex:indexPath.section]; - - UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[data objectForKey:@"image"]]]]; + NSDictionary *metadata = [_data objectAtIndex:indexPath.section]; + NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:metadata[@"image"]]]; + + UIImage *image = [[UIImage alloc] initWithData:data]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; CGFloat height = imageView.frame.size.height; - return height; } --(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { - NSDictionary *data = [self.datao objectAtIndex:section]; + NSDictionary *data = [_data objectAtIndex:section]; - UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,40)]; + UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 40)]; customView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0f alpha:1.0]; customView.alpha = 0.8999999999; customView.opaque = NO; [customView.layer setOpaque:NO]; - UILabel *titulo = [[UILabel alloc]initWithFrame:CGRectMake(8, 10, 255, 20)]; - titulo.text = [data objectForKey:@"name"]; - titulo.backgroundColor = [UIColor clearColor]; - [customView addSubview:titulo]; + UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(8, 10, 255, 20)]; + title.text = data[@"name"]; + title.backgroundColor = [UIColor clearColor]; + [customView addSubview:title]; return customView; } @@ -74,27 +71,24 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger return 1; } --(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - NSDictionary *data = [self.datao objectAtIndex:indexPath.section]; + NSDictionary *data = [_data objectAtIndex:indexPath.section]; static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - - UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[data objectForKey:@"image"]]]]; - + + UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:data[@"image"]]]]; UIImageView *imageViewo = [[UIImageView alloc] initWithImage:image]; CGFloat width = imageViewo.frame.size.width; CGFloat height = imageViewo.frame.size.height; //The UIImage, set with the url before announced UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; - [imageView sd_setImageWithURL:[NSURL URLWithString:[data objectForKey:@"image"]]]; + [imageView sd_setImageWithURL:[NSURL URLWithString:data[@"image"]]]; CGRect frame = [self.tableView rectForRowAtIndexPath:indexPath]; imageView.center = CGPointMake(cell.contentView.bounds.size.width/2,frame.size.height/2); @@ -116,10 +110,10 @@ - (void)didReceiveMemoryWarning // Dispose of any resources that can be recreated. } -- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if ([self.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]){ - return [self.delegate tableView:self.tableView didSelectRowAtIndexPath:indexPath]; + if ([_delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) { + return [_delegate tableView:_tableView didSelectRowAtIndexPath:indexPath]; } }