просмотр таблицы - PullRequest
       3

просмотр таблицы

0 голосов
/ 17 октября 2011

Я хочу создать UITableView, который имеет много столбцов, поэтому вся ячейка не может отображать все данные, а в первом столбце отображаются заголовки, эта строка не может перемещаться ровно, но другие строки могут перемещаться плоско.Я попытался добавить UITableView в UIScrollView, но не смог

Есть ли способы выполнить это требование?

1 Ответ

0 голосов
/ 17 октября 2011

Вам нужно сделать собственный TableViewCell, чтобы добиться этого правильно.

EDIT: Быстрый пример:

#import <UIKit/UIKit.h>

@interface MultiColumnTableViewCell : UITableViewCell
{
    UIButton *leftButton;
    UIButton *middleButton;
    UIButton *rightButton;
}

@property (nonatomic,retain) UIButton *leftButton;
@property (nonatomic,retain) UIButton *middleButton;
@property (nonatomic,retain) UIButton *rightButton;

@end


#import "MultiColumnTableViewCell.h"

    @implementation MultiColumnTableViewCell

    @synthesize leftButton;
    @synthesize middleButton;
    @synthesize rightButton;

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
            // Initialization code
            leftButton = [[UIButton alloc] init];
            [leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            leftButton.titleLabel.textAlignment = UITextAlignmentCenter;
            leftButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
            leftButton.titleLabel.numberOfLines = 2;

            middleButton = [[UIButton alloc] init];
            [middleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            middleButton.titleLabel.textAlignment = UITextAlignmentCenter;
            middleButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
            middleButton.titleLabel.numberOfLines = 2;

            rightButton = [[UIButton alloc] init];
            [rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            rightButton.titleLabel.textAlignment = UITextAlignmentCenter;
            rightButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
            rightButton.titleLabel.numberOfLines = 2;
        }
        return self;
    }

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        [super setSelected:selected animated:animated];

        // Configure the view for the selected state
    }

    @end

Быстрое использование в виде таблицы:

- (MultiColumnTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{   
    static NSString *CellIdentifier = @"Cell";

    MultiColumnTableViewCell *cell = (MultiColumnTableViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[MultiColumnTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Set up the cell...
    float tableviewWidth = self.myTableView.frame.size.width/3;
    int irow = indexPath.row;

    NSString *cellValue = myString;

    cell.leftButton.frame = CGRectMake(0, 0, tableviewWidth, 64.0);
    cell.leftButton.tag = someTag;
    [cell.leftButton setTitle:cellValue forState:UIControlStateNormal];
    [cell.leftButton addTarget:self action:@selector(someAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:cell.leftButton];

    cellValue = someOtherString;
    cell.middleButton.frame = CGRectMake(tableviewWidth, 0, tableviewWidth, 64.0);
    cell.middleButton.tag = someOtherTag;
    [cell.middleButton setTitle:cellValue forState:UIControlStateNormal];
    [cell.middleButton addTarget:self action:@selector(someOtherAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:cell.middleButton];

    cellValue = yetAnotherString
    cell.rightButton.frame = CGRectMake(tableviewWidth*2, 0, tableviewWidth, 64.0);
    cell.rightButton.tag = yetAnotherTag;
    [cell.rightButton setTitle:cellValue forState:UIControlStateNormal];
    [cell.rightButton addTarget:self action:@selector(yetAnotherAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:cell.rightButton];

    return cell;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...