UITableView cell not diplaying images horizontally
I want to have only one uitableview cell which can display horizontally as many images as it receives from server. But the problem is currently I receive say 15 images from the server and the cell only displays first开发者_运维百科 6 images and does not display rest 9 images. However, I can see the horizontal scroller scrolling till the end as i have made the contentsize according to size of 15 images. Following is the code (for testing purpose I am retrieving image from resource folder instead of getting from server ).
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
CGFloat imageXCordinate = 0.0;
int i =0;
for(i=0; i < 15; i++)
{
NSString *filePathForIconPhotoImage = [[NSBundle mainBundle] pathForResource:@"icon_photo" ofType:@"png"];
UIImage *iconPhoto = [[UIImage alloc] initWithContentsOfFile:filePathForIconPhotoImage];
UIImageView *vwIcon=[[UIImageView alloc] initWithFrame:CGRectMake(imageXCordinate,2,iconPhoto.size.width,iconPhoto.size.height) ] ;
vwIcon.image =iconPhoto;
[cell.contentView addSubview:vwIcon];
[vwIcon release];
[iconPhoto release];
imageXCordinate = imageXCordinate + basePhoto.size.width;
}
[tableView setContentSize:CGSizeMake((basePhoto.size.width * i, tableView.frame.size.height)];
}
NOTE: 1. I know I can use a UIScrollView instead but still want to use UITableView for some specific reasons. 2. I have created a UITableView programmatically and placed it in the [self.view addSuvView:myTableView].
Thanks in advance.
following link will definitely help you
how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2
精彩评论