2011-02-23 104 views
1

我想添加一個單元格的邊距。我用不同的方法嘗試過很多次,但都失敗了。請幫忙!以編程方式在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; 


} 

再次感謝。

回答

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 找到這個圖像的高度在這裏設置。 這是返回單元格大小的方法。

問候,

希亞姆帕爾馬

+0

我該如何去實施我的項目?我發佈了上面的代碼... – iosfreak 2011-02-23 05:28:30

+0

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60; } – GameLoading 2011-02-23 05:30:20

+0

這沒有做一件事。我之前和之後添加它,它仍然無法正常工作。我的縮略圖似乎卡在電池頂部和底部。 – iosfreak 2011-02-23 05:50:28

0

Shayam的答案是有點過時,不再編譯。

此外,如果您修復它,您可能會創建一個無限循環。正如Oded Regev所說,這不是做到這一點的方法。

+0

這種方法仍然可以在ios7中使用最新的xcode,沒有什麼是過時的.... relx。 – GameLoading 2013-08-29 18:01:12

相關問題