2010-08-26 56 views
-1
- (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]; 
    } 

,如果我想改變細胞之間的空間笏我甲肝在此代碼改變....我想和他們之間的一些差距,以顯示錶視圖細胞

與此代碼現在

我能夠如果你在談論

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

:如果你在談論的細胞的垂直高度有一定的差距,顯示細胞,但我不明白的是如何定義的差距...

回答

2

,更改此代碼水平的空間在單元格中的數據之間的E,你需要在這裏修改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)]; 

下一次約你問得越來越清晰。並且不要忘記接受你問的問題的答案。乾杯