我想添加一个单元格的边距。我用不同的方法尝试过很多次,但都失败了。请帮忙!以编程方式在UITableView单元格中添加边距?
- (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;
}
再次感谢。
我该如何去实施我的项目?我发布了上面的代码... – iosfreak 2011-02-23 05:28:30
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60; } – GameLoading 2011-02-23 05:30:20
这没有做一件事。我之前和之后添加它,它仍然无法正常工作。我的缩略图似乎卡在电池顶部和底部。 – iosfreak 2011-02-23 05:50:28