开发者

i want to display cells in table view with some gap between them

开发者 https://www.devze.com 2023-01-13 13:02 出处:网络
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [topics count];
-  (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];
  开发者_Go百科      [resViewController release];
    }

if i want to change space between cells wat i hav to change in this code ....

now with this code i am able to display cells with some gap but i didnt understand how the gap defined...


If you're talking about vertical height of the cells, change this code:

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

If you're talking about the horizontal space between data in the cell, you need to modify the CGRects here:

   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)];

Next time be a little more clear about what you're asking. And don't forget to accept answers to questions you ask. Cheers


I think maybe you need a look at this SO question:

How to give space between two cells in tableview?

0

精彩评论

暂无评论...
验证码 换一张
取 消