나는 IOS 개발로 시작했으며 첫 번째 클라이언트 프로젝트에 있습니다.TableView에 동적으로 여러 이미지 추가
나는 다음과 같은 장소에서 막혔어요 :이 달 10 사람의 생일이있는 경우
그래서, 내가 한 행에 10 imageviews (사진 3, 사진 3 장과 1 장의 사진)를 표시해야합니다.위 사람이 나를 도울 수 있습니까? 대단히 감사하겠습니다.
나는 IOS 개발로 시작했으며 첫 번째 클라이언트 프로젝트에 있습니다.TableView에 동적으로 여러 이미지 추가
나는 다음과 같은 장소에서 막혔어요 :이 달 10 사람의 생일이있는 경우
그래서, 내가 한 행에 10 imageviews (사진 3, 사진 3 장과 1 장의 사진)를 표시해야합니다.위 사람이 나를 도울 수 있습니까? 대단히 감사하겠습니다.
tableview에 이미지/레이블/버튼을 추가하려면 가장 간단한 방법은 UITableViewCell을 하위 클래스로 만드는 것입니다. 예를 들어 이미지가 5 개 (그림 3 장, 그림 3 장, 그림 1 개를 이해하지 못함)이고 원하는 경우
이 CustomCell라는 이름의 프로젝트에 새 파일을 추가과 같이있는 UITableViewCell의 하위 클래스해야한다 : 당신이 뭔가 할 수있는 테이블 행에서 그들을 보여
@interface CustomCell : UITableViewCell {
UIImageView *imageView1;
UIImageView *imageView2;
UIImageView *imageView3;
UIImageView *imageView4;
UIImageView *imageView5;
}
@property (nonatomic, retain) UIImageView *imageView1;
@property (nonatomic, retain) UIImageView *imageView2;
@property (nonatomic, retain) UIImageView *imageView3;
@property (nonatomic, retain) UIImageView *imageView4;
@property (nonatomic, retain) UIImageView *imageView5;
@end
을 그리고 CustomCell.m에서 다음 코드를 입력하십시오 :
@synthesize imageView1, imageView2, imageView3, imageView4, imageView5;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 50, 45)];
[self.contentView addSubview:imageView1];
self.imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(65, 8, 50, 45)];
[self.contentView addSubview:imageView2];
self.imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(120, 8, 50, 45)];
[self.contentView addSubview:imageView3];
self.imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(170, 8, 50, 45)];
[self.contentView addSubview:imageView4];
self.imageView5 = [[UIImageView alloc] initWithFrame:CGRectMake(225, 8, 50, 45)];
[self.contentView addSubview:imageView5];
}
return self;
}
은 그래서 당신은 당신의 뷰 컨트롤러에서 사용하는 방법을 UITableViewCell.Now의 서브 클래스로 완료?
는이 같은 어떤 것을 할cellForRowAtIndexPath 위임 방법에보기 컨트롤러 class.And에 CustomCell.h를 가져올 수 있습니다
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
//our custom cell
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell.
//cell.imageView1.image = [UIImage imageNamed:@"testImg1"];
//cell.imageView2.image = [UIImage imageNamed:@"testImg2"];
//cell.imageView3.image = [UIImage imageNamed:@"testImg3"];
//cell.imageView4.image = [UIImage imageNamed:@"testImg4"];
//cell.imageView5.image = [UIImage imageNamed:@"testImg5"];
//return cell;
는 u는 더 사용할 수였다 :
NSMutableArray *imgArray = [[NSMutableArray alloc] initWithObjects:cell.imageView1, cell.imageView2,cell.imageView3, cell.imageView4, cell.imageView5, nil];
for (int imageCounter = 0; imageCounter<5; imageCounter++) {
[[imgArray objectAtIndex:imageCounter] setImage:[UIImage imageNamed:[NSString stringWithFormat:@"testImg%d", imageCounter]]];
}
return cell;
}
이것은 문제의 맥락을위한 매우 원형의 해결책입니다.
희망이 있다면 도움이 될 것입니다.
도움 주셔서 감사합니다. 나는 그것을 시험해 볼 것이고 그것이 나를 위해 일하면 갱신 할 것이다. –
고마워, 이건 정말 도움이 내 문제를 해결 :) –
다행 내가 도울 수 : – Alok
- (UITableViewCell *)tableView:(UITableView *)tTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
for (int t =0; t<cell.subviews.count; t=t) {
if (![[[cell.subviews objectAtIndex:t].class]isEqualToString:@"UIImageView"]) {
t++;
}
else {
[((UIView*)[[cell.subviews objectAtIndex:t])removeFromSuperview];
}
}
}
for (int t = 0; t<10; t++) {
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(cell.frame.size.width/10*t, 0, cell.frame.size.width/10, cell.frame.size.height)];
[imageView setImage:[UIImage imageNamed:<#(NSString *)#>]];
[cell addSubview:imageView];
}
return cell;
}
(3 장의 사진, 3 장의 사진 및 1 장의 사진) 당신이 무엇을 의미하는지 모르겠지만 거기에서 알아낼 수 있어야합니다.
테이블 뷰에서 행을 묻는 때마다 매번 ... 심지어 그 행이 그냥 스크롤 된 다음 다시 돌아 오는 행을 제안하는 것처럼 보입니다. UIImage 뷰를 10 개 할당하고 하위 뷰로 쌓아 두는 것이 좋습니다. 애매한 질문에 대해 지나치게 가혹한 처벌이 아닌가? – danh
이전 버전을 제거하거나 다시 사용하고 싶을 수도 있습니다. 또 다른 방법은 설정할 수있는 10 개의 이미지 뷰를 사용하여 UITableViewCell의 하위 클래스를 만드는 것이지만 각 셀에 최대 10 개의 그림이 필요합니다. –
미정의 사진을 원한다면 내가 준 사진을 시험해보고 휴지통에 담기가 아니라 객체를 재사용하여 리메이크하도록 수정하십시오. 사용하지 않는 경우 http://stackoverflow.com/a/10399483/1354623 –
downvote 화살표를 가져 가면 downvoting의 원인을 확인한 다음 질문을 다시 읽습니다. 여기에있는 사람들은 당신을 도와 주거나 길을 안내해 줄 것이며, 당신을 위해 일하지 않습니다. – psycho
@Vishal Aggarwal : - ur 요구 사항을 자세하게 설명합니다. 표보기 셀에 이미지를 표시 하시겠습니까? 또는보기에서? 테이블 뷰 셀에 10 개의 이미지를 표시하려면 두 가지 접근 방식을 구현해야합니다. 1- 테이블 셀 또는 U를 사용자 정의하려면 - 'Pulse'스타일 스크롤 만들기 - UITableView를 UITableViewCell의 하위보기로 가로로 스크롤합니다. 먼저 상세하게 귀하의 요구 사항을 말해주십시오. 그 후에 당신을 도우 려합니다. 그리고 우리 모두가 성공하기를 바랍니다 :-) –
@psycho - 정보가 부족하여 불쌍히 여겨서 미안합니다. 나는 방금 훈련을 마친 초보자입니다. 내가 배우면 분명히 좋아질 것입니다. :) –