В UITableView создайте одну настраиваемую ячейку с 3 изображениями в одной ячейке и отобразите изображения. Функциональность зависит от моего массива, но в NSLog я не получаю правильный счет ... также, когда вызывается cellForRowAtIndexPath:
, вызывается первое условие if
; он не входит в else if
.Как показать три изображения в одной строке с помощью пользовательской ячейки в Objective c?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(@"cell:%f", ceil(((float)[arrData count])/3.0));
return ceil(((float)[arrData count])/3.0);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
PhotosCell *cell = (PhotosCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PhotosCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if (arrData.count-1 >=indexPath.row * 3) {
cell.btnFst.tag = indexPath.row+1;
[cell.btnFst setTitle:[arrData objectAtIndex:(indexPath.row*3)] forState:UIControlStateNormal];
[cell.btnFst addTarget:self action:@selector(btnDidSelected:) forControlEvents:UIControlEventTouchUpInside];
} else if (arrData.count-1 >=(indexPath.row*3)+1) {
cell.btnFst.tag = indexPath.row+2;
[cell.btnFst setTitle:[arrData objectAtIndex:(indexPath.row*3)+1] forState:UIControlStateNormal];
[cell.btnFst addTarget:self action:@selector(btnDidSelected:) forControlEvents:UIControlEventTouchUpInside];
} else if (arrData.count-1 >=(indexPath.row*3)+2) {
cell.btnFst.tag = indexPath.row+3;
[cell.btnFst setTitle:[arrData objectAtIndex:(indexPath.row*3)+2] forState:UIControlStateNormal];
[cell.btnFst addTarget:self action:@selector(btnDidSelected:) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
что ваш вопрос? –
Прежде всего, ваш вопрос не ясен, но может быть его работой для вас, поэтому положите только условие 'if' remove' else if' .. – iPatel
Я думаю, что ceil возвращает double (ceilf возвращает float), а numberOfRowsInSection должен возвращать NSInteger (не double или float) – Bamsworld