2012-05-04 45 views
0

我有一個場景,我想保留tableview的行上的圖像的「縮略圖」。我在運行時決定連續排列的圖像數量。其次,點擊任何圖像我想啓動一個視圖控制器與詳細描述它的形象。UItableView具有多個圖像,並在其中每一個上設置onclick

我該如何做到這一點?

|________________| 
| 1 2 3 4 5 6 | 
|________________| 
| 7 8 9 10 11 12 | 
|________________| 
| 12 14 15  | 
|________________| 

想象一下上面的數字作爲縮略圖。點擊任何數字我想啓動一個新的視圖控制器,提供有關圖像的詳細信息。

代碼片段:

-(void) populateTableView 
{ 

    NSMutableArray* srcArray = [[NSMutableArray alloc] initWithArray:[[ImageDataSource sharedImageDataSource] getThumbnailsSrcArray]]; 

    int noOfImages = srcArray.count; 

    float rowc = (noOfImages/ROW_ELEM_COUNT) + 0.5; 

    int rowCount = roundf(rowc); 

    titleData = [[NSMutableArray alloc]init]; 

    int j=0; 
    for (int i=0; i<rowCount; i++) { 

     NSMutableArray* rowArray = [[NSMutableArray alloc] init]; 

     for (int k=0; k < ROW_ELEM_COUNT; k++) { 

      if (j < noOfImages) { 
       NSString* imgPath = [srcArray objectAtIndex:j]; 
       UIImage* img = [[UIImage alloc] initWithContentsOfFile:imgPath]; 
       [rowArray addObject:img]; 
       [img release]; 
       imgPath=nil; 
      } 
      j++; 
     } 
     [titleData addObject:rowArray]; 
    } 

    titleView = [[UITableView alloc] initWithFrame:CGRectMake(90.0,156.0,590.0,630.0) 
              style:UITableViewStyleGrouped]; 
    titleView.delegate = self; 

    [self.view addSubview:titleView]; 
    [titleView release]; 

} 

所以基本上我有數組作爲我的DS的陣列。每個數組的索引將是表格視圖的行,並且數組裏面將會有圖像。但我不知道如何填充tableview。 任何線索任何人?

回答

1

你有兩種選擇。

•在UIImage中添加一個UIButton,並將每個按鈕作爲子視圖添加到您的tableview單元格中。

•找出其中對小區內的用戶挖掘並從這裏計算他們抽頭的圖像和要執行的操作:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch* touch = [touches anyObject]; 
    // do your stuff 
    //.. 
} 
+0

我一定要繼承的UITableViewCell與否?如果我們在 - (UITableViewCell *)中創建它們應該沒問題。tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath –

+0

是的,您可以輕鬆地將子視圖添加到單元格中。 contentView'在這個方法中。 – runmad

相關問題