gpt4 book ai didi

objective-c - 将图像和滚动图标添加到 TableView 的逻辑

转载 作者:行者123 更新时间:2023-11-28 20:46:04 25 4
gpt4 key购买 nike

我有一个表格 View ,我在一行中添加了四个 UIImageView,所以我总共有五行和二十个 ImageView 。我正在将图像一张一张地插入到单元格中。只有当所有四个 ImageView 都被填充后,第二行才会开始填充。

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

还有什么方法可以从一行中单独选择图像吗?

最佳答案

运行这段代码:-

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

}

关于objective-c - 将图像和滚动图标添加到 TableView 的逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6288588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com