i have a table view and i want to add image on it by using the following code,
first by overriding layoutSubviews
- (void)layoutSubviews{
[super layoutSubviews];
self.imageView.frame = CGRectMake(15, 5, 50, 45);
self.imageView.layer.cornerRadius = 5.0f;
self.imageView.layer.masksToBounds = YES;
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
}
and then using it in the -(MyTableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
NSString *imageUrlString = [userInfoResponse[indexPath.row - beginIndex] objectForKey:@"image_url"];
NSURL * imageURL = [NSURL URLWithString:imageUrlString];
if ( [[NSUserDefaults standardUserDefaults] objectForKey:imageUrlString] == nil ) {
[[NSUserDefaults standardUserDefaults] setObject:[NSData dataWithContentsOfURL:imageURL] forKey:imageUrlString];
}
UIImage * img = [UIImage imageWithData:[[NSUserDefaults standardUserDefaults] objectForKey:imageUrlString]];
cell.imageView.image = img;
}
and in this line i added
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 55.0;
}
it works fine with this little problem (see attached image). I don't want the cell border line to be interrupted by the image.
I tried playing on codes but it wont help. Anyone knows the answer? please help. Thanks
NOTE: It works well with iOS 6, this screenshot is on iOS 7. Can it be a new settings for iOS 7 UITableView
?
Go to your table view controller and put these codes into viewDidLoad:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) //should check version to prevent force closed
{
self.tableView.separatorInset = UIEdgeInsetsZero;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With