я хочу отображать ячейки в табличном представлении с некоторым промежутком между ними - PullRequest
0 голосов
/ 26 августа 2010
-  (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [topics count];
    }

    - (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {

        CGRect cellFrame = CGRectMake(0,0,320,45);  
        UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:cellIdentifier] autorelease];

        CGRect bgFrame = CGRectMake(10,5,300,35);   
        UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"list_bg_up.png"]];
        backgroundView.frame = bgFrame;
        [cell addSubview:backgroundView];

        UILabel *txtLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,10,250,25)];
        txtLabel.textColor=[UIColor whiteColor];
        txtLabel.backgroundColor = [UIColor clearColor];
        txtLabel.tag = 1;
        [cell addSubview:txtLabel];

        return cell;
    }   

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

        UITableViewCell *cell;

        static NSString *kDisplayCell_ID = @"DisplayCellID";

        //cell = [self.tableView dequeueReusableCellWithIdentifier:kDisplayCell_ID];
        cell = [tableView dequeueReusableCellWithIdentifier:kDisplayCell_ID];

        if(cell == nil) {
            cell = [self getCellContentView:kDisplayCell_ID];
        }

        aTopic = [topics objectAtIndex:indexPath.row];
        UILabel *txtLabel = (UILabel *)[cell viewWithTag:1];
        txtLabel.text = aTopic.description;

        return cell;
    }

    -(CGFloat)tableView:(UITableView *)tbView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return 45;
    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        ResourcesViewController *resViewController = [[ResourcesViewController alloc] initWithNibName:@"ResourcesViewController" bundle:[NSBundle mainBundle]];
        resViewController.aTopic = [topics objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:resViewController animated:YES];
        [resViewController release];
    }

если я хочу изменить расстояние между ячейками, то я должен изменить этот код ....

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

Ответы [ 2 ]

2 голосов
/ 27 августа 2010

Если вы говорите о вертикальной высоте ячеек, измените этот код:

-(CGFloat)tableView:(UITableView *)tbView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return 45;
    }

Если вы говорите о горизонтальном пространстве между данными в ячейке, вам нужно изменить CGRects здесь:

   CGRect cellFrame = CGRectMake(0,0,320,45);  
        UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:cellIdentifier] autorelease];

        CGRect bgFrame = CGRectMake(10,5,300,35);   
        UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"list_bg_up.png"]];
        backgroundView.frame = bgFrame;
        [cell addSubview:backgroundView];

        UILabel *txtLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,10,250,25)];

В следующий раз немного яснее о том, что вы спрашиваете.И не забывайте принимать ответы на вопросы, которые вы задаете.Приветствия

0 голосов
/ 01 августа 2013

Я думаю, что, возможно, вам нужно взглянуть на этот вопрос SO:

Как указать расстояние между двумя ячейками в табличном представлении?

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