Подтвердить что ты не робот

Как добавить флажки в UITableViewCell?

некоторое время назад кто-то уже задавал этот вопрос, и было дано несколько ответов, но я действительно не понимал их. Так что мне было интересно, может ли кто-нибудь написать простой учебник о том, как сделать то, что показано на изображении ниже:

http://img208.yfrog.com/img208/6119/screenshotkmr.png

Я был бы так любезен, если бы кто-нибудь мог поделиться именно этим, потому что это выглядит действительно круто, и я хотел бы использовать что-то подобное в своем приложении: -)!

4b9b3361

Ответ 1

Сделайте непроверенное и проверенное изображение.

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    if ([selectedRowsArray containsObject:[contentArray objectAtIndex:indexPath.row]]) {
        cell.imageView.image = [UIImage imageNamed:@"checked.png"];
    }
    else {
       cell.imageView.image = [UIImage imageNamed:@"unchecked.png"];
    }
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleChecking:)];
    [cell.imageView addGestureRecognizer:tap];
    cell.imageView.userInteractionEnabled = YES; //added based on @John  comment
    //[tap release];

    cell.textLabel.text = [contentArray objectAtIndex:indexPath.row];
    return cell;
}

- (void) handleChecking:(UITapGestureRecognizer *)tapRecognizer {
    CGPoint tapLocation = [tapRecognizer locationInView:self.tableView];
    NSIndexPath *tappedIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation];

    if ([selectedRowsArray containsObject:[contentArray objectAtIndex:tappedIndexPath.row]]) {
        [selectedRowsArray removeObject:[contentArray objectAtIndex:tappedIndexPath.row]];
    }
    else {
        [selectedRowsArray addObject:[contentArray objectAtIndex:tappedIndexPath.row]];
    }
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:tappedIndexPath] withRowAnimation: UITableViewRowAnimationFade];
}

Ответ 2

Один из способов, о котором я могу думать, - это настроить UITableViewCell (этот учебник для начала. Это другой, аналогичный). Внутри пользовательского UITableViewCell вам нужно разместить UIButton с изображением круга. Когда пользователь выбирает кнопку, вы меняете изображение на зеленый круг