Iphone 我想在表格视图中显示单元格,它们之间有一些间隙
如果我想改变单元格之间的空间,我必须在这个代码中改变Iphone 我想在表格视图中显示单元格,它们之间有一些间隙,iphone,xcode,uitableview,Iphone,Xcode,Uitableview,如果我想改变单元格之间的空间,我必须在这个代码中改变 现在有了这段代码,我可以显示一些有间隙的单元格,但我不知道间隙是如何定义的…如果您谈论的是单元格的垂直高度,请更改这段代码: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [topics count]; } - (UITableViewCell *) getC
现在有了这段代码,我可以显示一些有间隙的单元格,但我不知道间隙是如何定义的…如果您谈论的是单元格的垂直高度,请更改这段代码:
- (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];
}
如果您讨论的是单元格中数据之间的水平间距,则需要在此处修改CGRECT:
-(CGFloat)tableView:(UITableView *)tbView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 45;
}
下次你要更清楚地知道你在问什么。别忘了接受你所问问题的答案。干杯我想也许你需要看看这个问题:
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)];