У меня много проблем. Я новичок в разработке ios, поэтому любая помощь приветствуется.Динамически добавлять изображение в пользовательскую ячейку и назначать ему изображение
Проблема первой
Я хочу, чтобы отобразить N количества изображений ракурса + наклейку над желтыми и синим изображениями в пользовательской ячейке.
Мне нужно разобрать, сколько изображений изображения будет отображаться на каждой строке, и в соответствии с этим мне нужно назначить изображение для каждого изображения в моей пользовательской ячейке. Как я могу это сделать? Я извлекаю ссылки на изображения из базы данных и сохраняю их в массиве, но как я могу применить ссылки к определенному представлению изображения в строке.
Просто нужны подсказки для построения выше пользовательского интерфейса в iOS.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifierLeft = @"lefthand";
static NSString *CellIdentifierRight = @"righthand";
if (indexPath.row % 2 == 1) // to get two custom cell vice versa.
{
LeftCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierLeft];
if (LeftCell == nil)
{
LeftCell = [[customCellLeft alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierLeft row:indexPath.row];
LeftCell.scrollView = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(0,14,1024,187)];
}
LeftCell.videoImageView1.tag=[ImageLinkArray objectAtIndex:indexPath.row];
LeftCell.label1.text=[TitleArray objectAtIndex:indexPath.row];
return LeftCell;
}
else
{
RightCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierRight];
if(RightCell == nil)
{
RightCell =[[customCellRight alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierRight];
RightCell.scrollView = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(0,14,1024,187)];
}
RightCell.videoImageView1.tag=[ImageLinkArray objectAtIndex:indexPath.row];
RightCell.label1.text=[TitleArray objectAtIndex:indexPath.row];
return RightCell;
}
Пользовательский код класса клетка ...
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier row:(int)row
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
int indexNumber; // variable to store Array index number
int VideoNumber=3; // imageview in particular cell + Train Engine.
scrollView = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(33,14,958,187)]; // Scrollview
scrollView.scrollEnabled=YES;
scrollView.userInteractionEnabled=YES;
scrollView.showsHorizontalScrollIndicator=NO;
scrollView.contentSize = CGSizeMake((335*VideoNumber),187); // To make ContentSize for item to scroll
for (int i = 0; i < VideoNumber; i++)
{ // for loop to add 2 wagon view and 1 engine view on Left hand side Custom cell.
if(i==0) // to check first item must be train Engine
{
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 18;
frame.size.width=186;
frame.size.height= 162;
UIView *EngineView = [[UIView alloc]initWithFrame:frame];
UIImageView *engineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 6, 186, 162)];
UIImage *Image = [UIImage imageNamed:@"loco_left.png"];
engineImageView.image = Image;
[EngineView addSubview:engineImageView];
[scrollView addSubview:EngineView]; // add 1st imageview that is Train Engine to first of scrollview
}
else
{ // else it must be wagon of train.
indexNumber=row*(VideoNumber-1)+(i-1);// to get Index Number of array to to display Images as per cell number
NSLog(@"at Normal row index number is %d",indexNumber);
CGRect frame;
frame.origin.x = (385*i)-432;
frame.origin.y = 18;
frame.size.width=385;
frame.size.height= 163;
UIView *wagon = [[UIView alloc]initWithFrame:frame];
UIImageView *wagonImage = [[UIImageView alloc]initWithFrame:CGRectMake(230, 6, 385, 163)];
UIImage *Image = [UIImage imageNamed:@"wagon_left.png"];
wagonImage.image = Image;
[wagon addSubview:wagonImage];
UIView *videoviewContainer = [[UIView alloc]initWithFrame:CGRectMake(15, 30, 190 , 200)];
videoImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 190, 100)];
UIImage *bgImage = [UIImage imageNamed:@"video.png"];
videoImageView2.image = bgImage;
videoviewContainer.contentMode = UIViewContentModeLeft; // set Video Image view to left hand side of wagon UIView
videoImageView2.tag=indexNumber;
[videoviewContainer addSubview:videoImageView2];
UITapGestureRecognizer *video = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(VideoItemOne:)];
[videoImageView2 addGestureRecognizer:video];
[videoImageView2 setMultipleTouchEnabled:YES];
[videoImageView2 setUserInteractionEnabled:YES];
UIView *textUiView = [[UIView alloc]initWithFrame:CGRectMake(208,28, 150 , 187)];
textUiView.contentMode = UIViewContentModeRight;
label2 = [[UILabel alloc]initWithFrame:CGRectMake(28,10, 150 , 87)];
label2.text=[TitleArray objectAtIndex:indexNumber];
label2.backgroundColor = [UIColor clearColor];
label2.textColor=[UIColor redColor];
label2.numberOfLines = 4;
[textUiView addSubview:label2];
[wagonImage addSubview:textUiView];
[wagonImage addSubview:videoviewContainer];
[scrollView addSubview:wagon];
}
}
[self.contentView addSubview:scrollView];
}
return self;
}
-(void)populateWithImage:myImage andText:myText
{
[videoImageView2 setImageWithURL:[NSURL URLWithString:myImage]
placeholderImage:[UIImage imageNamed:@"video.png"]];
}
Разделите свои вопросы на разные должности. Это облегчит сообществу ответы на ваши вопросы. –
@JeffWolski Хорошо, я отредактирую второй вопрос .. и после того, как я получу 1-й ответ, я опубликую второй номер –
Когда вам нужно создать разные ячейки, вы все равно можете использовать ячейки повторно, получив сброс, который очистит subviews, а затем их стиль согласно требованию. –