2012-01-03 50 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 

這將是我寫過的最長的答案!