向表视图添加图像和滚动图标的逻辑 [英] Logic for adding images and scroll icon to the table view

查看:53
本文介绍了向表视图添加图像和滚动图标的逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格视图,我要在一行中添加四个 UIImageView s,所以总共我有五行和二十个图像视图。我正在一张一张地插入图像。一旦填充了所有四个图像视图,第二行将开始填充。

I have a table view, and I am adding four UIImageViews to a row, so in total I have five rows and twenty image views. I am inserting images one by one into the cell. The second row will only start to fill once all four image views are filled.

我需要一些逻辑。我的意思是,我该如何检查表格视图中接下来要填充的位置以及哪个事件?如何将图像一个接一个地添加到 UIImageView 中?同样,最初仅显示两行。填充这两行之后,当图像开始进入第三行时,我需要在屏幕上最后一行的旁边显示一个图标,以告诉用户下面有更多数据。另外,是否有任何事件可以检测当前屏幕上的最后一行?

I need some logic for this. I mean, how can I check which place is next to be filled in the table view and at which event? How can I add images one by one to the UIImageViews? Also, initially only two rows will be shown. After filling these two rows, when images begin to enter into the third row, I need to show an icon adjacent to the last row that is on the screen, to tell the user that there is more data below. Also, is there any event to detect which row is currently the last row on screen?

还有没有办法从一行中单独选择图像?

Also is there any way to individually select the images from a row?

推荐答案

运行以下代码:-

.h file code


#import <UIKit/UIKit.h>

@interface helpTableViewController : UIViewController {
    IBOutlet UITableView *gridTableView;
    NSMutableArray *imagesArray;
    int widthview,widthview1;

    }
@property(nonatomic,retain)NSMutableArray *imagesArray;
@property(nonatomic,retain)UITableView *gridTableView;
-(UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier withIndexPath:(NSIndexPath *)indexPath;
-(void)crossViewButtonClicked:(UIButton *)sender;

@end

.m文件代码:-

@synthesize gridTableView;
@synthesize imagesArray;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableArray *tempArray=[[NSMutableArray alloc]init];
    self.imagesArray=tempArray;
    [tempArray release];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic1.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic2.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic3.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic4.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic5.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic6.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic1.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic2.png"]];
    [self.imagesArray addObject:[UIImage imageNamed:@"pic3.png"]];
    widthview=0;
    widthview1=0;
}

- (void)viewDidUnload {
    self.gridTableView=nil;
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [imagesArray release];
    [gridTableView release];
    [super dealloc];
}


#pragma mark -
#pragma mark TableView Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell=nil;
    if (cell == nil) {
        cell =[self reuseTableViewCellWithIdentifier:CellIdentifier withIndexPath:indexPath];

    }

            return cell;
}
-(UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier withIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:identifier]autorelease];
    if (indexPath.row==0) {
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 180)];
        scrollView.contentSize = CGSizeMake(320, 180);
        scrollView.backgroundColor=[UIColor clearColor];
        scrollView.showsHorizontalScrollIndicator = NO;
        [cell.contentView addSubview:scrollView];       
        for (int i=0; i<4;i++) {        
            UIView *profileView=[[UIView alloc]initWithFrame:CGRectMake(widthview+10, 12, 95, 155)];
            profileView.backgroundColor=[UIColor whiteColor];
            UIImageView *profileimageView=[[UIImageView alloc]initWithFrame:CGRectMake(5, 8, 83, 106)];
            [profileimageView setImage:[self.imagesArray objectAtIndex:i]];
            profileimageView.tag=i+90;
            [profileView addSubview:profileimageView];
            [profileimageView release];
            [scrollView addSubview:profileView];
            widthview=widthview+105;
            NSLog(@"%d",widthview);
        }
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setFrame:CGRectMake(widthview1+10, 12, 95, 155)];
        //button.contentMode = UIViewContentModeScaleAspectFill;
        button.tag=999999;
        [button setBackgroundColor:[UIColor greenColor]];
        [button addTarget:self action:@selector(imageButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:button];
        widthview=widthview+105;
        scrollView.contentSize = CGSizeMake(widthview, 180);

    }
    if (indexPath.row==1) {
        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 180)];
        scrollView.contentSize = CGSizeMake(320, 180);
        scrollView.backgroundColor=[UIColor clearColor];
        scrollView.showsHorizontalScrollIndicator = NO;
        [cell.contentView addSubview:scrollView];       
        for (int i=0; i<4;i++) {        
            UIView *profileView=[[UIView alloc]initWithFrame:CGRectMake(widthview1+10, 12, 95, 155)];
            profileView.backgroundColor=[UIColor whiteColor];

            UIImageView *profileimageView=[[UIImageView alloc]initWithFrame:CGRectMake(5, 8, 83, 106)];
            //  [profileimageView setImage:[UIImage imageNamed:@"gridimage1.png"]];
            profileimageView.tag=4+i;
            [profileimageView setImage:[self.imagesArray objectAtIndex:3+i]];
            [profileView addSubview:profileimageView];

            [scrollView addSubview:profileView];
            [profileimageView release];
            widthview1=widthview1+105;
            NSLog(@"%d",widthview1);
        }
        scrollView.contentSize = CGSizeMake(widthview1, 180);

    }return cell;

}

// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}
#pragma mark -
#pragma mark button methods


-(void)imageButtonClicked:(UIButton *)sender
{
    [self.imagesArray replaceObjectAtIndex:0 withObject:[UIImage imageNamed:@"abdulprofilepic.png"]];
    [self.gridTableView reloadData];

}

这篇关于向表视图添加图像和滚动图标的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆