1

I am trying to add margin to a cell. I have tried many times with different methods but have failed. Please help!

- (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;


}

Thanks again.

3 Answers 3

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
 }
}

// returns nil if cell is not visible or index path is out of range

check this method. find what what u got cell.imageview or cell.image find the height of that image here and set here. this is the method that return the size of the cell.

Regards,

Shyam Parmar

Sign up to request clarification or add additional context in comments.

9 Comments

How would I go about implementing that in my project? I posted more code above...
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60; }
That didn't do a thing. I added it before and after and it still doesn't work. My thumbnails seemed jammed against the top part of the cell and the bottom part.
Request for member 'frame' is something not of structure or union.
This is not the way to do it
|
0

Shayam's answer is a little outdated and no longer compiles.

Also, if you fix it you'll be likely to create an endless loop. As Oded Regev mentioned, this is not the way to do it.

1 Comment

this method is still available in ios7 with latest xcode,Nothing is outdated.... relx.
0

Please see the following question for a detailed overview on how to do.

How to add spacing between UITableViewCell

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.