2012-01-03 47 views
0

我想在来自服务器的TableView的每个单元格中显示多个图像,我不知道每个表格单元格中图像的确切数量。
当用户点击任何图像时,它会放大另一个视图控制器。
我的问题是如何设计这种动态高度的表格,以及如何知道哪些图像被放大缩小。
谢谢UITableViewCell中的多个图像,并在iPhone中附加操作

回答

2

我设计了与您目前正在使用的表格相同的表格。

因为我已经在每个tableview单元格中使用UIScrollview,所以来自服务器的图像将显示在滚动视图中。

为了显示滚动视图中的图像,我带了UIButton,以便识别哪个图像被按下。

这是我正在做的基本想法。

享受!

0

在这里,我们去:你需要一个自定义单元格来保存照片阵列。

您需要自定义UIImageView来跟踪触摸。为此,您有两个选项:在顶部添加一个按钮,或者使用-touchesBegan(请参见下文)。

现在,当你点击一张图片,它会告诉它的父母(单元格)哪张照片被按下。 单元格会将信息转发给RootViewController(带有UITableView的类),并将其自身添加到信息中。

类需要:

  • RootViewController的(这里未实现)
  • 细胞
  • CustomImageView

//Cell.h

进口的UIKit/UIKit.h

@class RootViewController; 
@class CustomImageView; 

@interface Cell : UITableViewCell 
{ 
RootViewController *parent; 
IBOutlet UIView *baseView; //I use this instead of content view; is more ..mutable 
NSMutableArray *photosArray; 
double cellHeight;  
} 

@property (nonatomic, assign) RootViewController *parent; 
@property (nonatomic, retain) UIView *baseView;  
@property (nonatomic, retain) NSMutableArray *photosArray;  
@property double cellHeight; 


(void) didClickPhoto: (CustomImageView*) image;  

@end 
//Cell.m 

import "Cell.h" 

@implementation Cell 

@synthesize baseView, photosArray, cellHeight, parent; 

- (void) didClickPhoto: (CustomImageView*) image 
{ 
    unsigned indexOfSelectedPhoto = [photosArray indexOfObject:image]; 
    //this will allow you to reffere the pressed image; 

    [parent didClickPhotoAtIndex: indexOfSelectedPhoto inCell: self]; 
    //you will inplement this function in RootViewController 
} 

@end 

CustomImageView.h

#import <UIKit/UIKit.h> 
#import "Cell.h" 

@interface CustomImageView : UIImageView { 
    Cell *parent; 
} 

@property (nonatomic, assign) Cell *parent; 
@end 

CustomImageView。m

#import "CustomImageView.h" 


@implementation CustomImageView 
@synthesize parent; 

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { 
    [parent didClickPhoto:self]; 
} 
@end 

这将是我写过的最长的答案!