0

I have a scenario where I want to keep "thumbnails" of images on the row of the tableview. I decide on runtime the numbers of images that goes in a row.

Secondly, On click of any of the image I want to launch a viewcontroller with elaborated image of it with some description.

How can I achieve this?

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

Imagine the numbers above as thumbnails. Onclick of any of the number I want to launch a new view controller which gives details about the image.

code snippet:

-(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];

}

So basically I have array of array as my DS. index of each array will be row of table view and the array inside will have images. But I am not sure how to populate the tableview. Any clue anybody?

4

1 回答 1

1

你有两个选择。

• 添加带有 UIImage 的 UIButton 并将每个按钮添加为您的 tableview 单元格上的子视图。

或者

• 找出用户在单元格上点击的位置,并从这里计算他们点击的图像以及要采取的操作:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touch = [touches anyObject];
    // do your stuff
    //..
}
于 2012-05-04T17:42:38.287 回答