我正在尝试为单元格添加边距。我用不同的方法尝试了很多次但都失败了。请帮忙!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
tableView.rowHeight = 60;
// InitWithStyle
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Get Selected Name
NSString *selectedCountry = [listOfItems objectAtIndex:indexPath.row];
// Set up the cell...
NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
cell.text = cellValue;
NSArray *resultstwoo = [database executeQuery:@"SELECT * FROM albums WHERE name=?", selectedCountry];
for (NSDictionary *rowtwoo in resultstwoo) {
NSString *connectionsText = [rowtwoo valueForKey:@"connections"];
cell.detailTextLabel.text = connectionsText;
}
// Get Selected ID
NSArray *resultsID = [database executeQuery:@"SELECT * FROM albums WHERE name=?", selectedCountry];
for (NSDictionary *rowID in resultsID) {
NSString *selectedIDtwo = [rowID valueForKey:@"id"];
// Get latest picture and Display
int imagesCount = 0;
NSArray *listOfItemsTwo = [database executeQuery:@"SELECT * FROM images WHERE album=? ORDER BY id DESC LIMIT 0,1", selectedIDtwo];
for (NSDictionary *rowone in listOfItemsTwo) {
imagesCount ++;
NSString *getDir = @"./../Documents/";
NSString *getID = [rowone valueForKey:@"id"];
NSString *getFile = @"_thumbnail.jpg";
NSString *theImagePath = [NSString stringWithFormat:@"%@%@%@",getDir, getID, getFile];
UIImage *theImage = [UIImage imageNamed:theImagePath];
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.image = theImage;
//cell.image = [theImage imageScaledToSize:CGSizeMake(38, 38)];
//NSLog(@"%@", theImage);
}
// If there is no images in the album, display generic picture
if (imagesCount == 0) {
UIImage *theImage = [UIImage imageNamed:@"noalbumimages"];
cell.imageView.image = theImage;
//NSLog(@"%@", theImage);
}
}
return cell;
}
再次感谢。
答案 0 :(得分:1)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
if(cell)
{
return cell.imageView.size.height+10;
}
else
{
return 44; //Return any default size you want
}
}
//如果单元格不可见或索引路径超出范围则返回nil
检查此方法。 找到你得到的cell.imageview或cell.image 在这里找到该图像的高度并在此处设置。 这是返回单元格大小的方法。
此致
Shyam Parmar
答案 1 :(得分:0)
Shayam的答案有点过时,不再编译。
另外,如果你修复它,你可能会创建一个无限循环。正如Oded Regev所说,这不是这样做的方式。
答案 2 :(得分:0)
请参阅以下问题,详细了解如何操作。