i have a table view and i want to add image on it by using the following code,
我有一个表格视图我想用下面的代码在上面添加图像,
first by overriding layoutSubviews
首先通过重写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
然后在- MyTableViewCell *中使用它:(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
?
注意:它在ios6上运行良好,这个截图在ios7上。它能成为ios7 UITableView的新设置吗?
5 个解决方案
#1
11
Go to your table view controller and put these codes into viewDidLoad:
转到您的表视图控制器,将这些代码放入viewDidLoad:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) //should check version to prevent force closed
{
self.tableView.separatorInset = UIEdgeInsetsZero;
}
#2
1
If you don't want to adjust the height of your UITableViewCell
then inside cellForRowAtIndexPath
use:
如果您不想调整UITableViewCell的高度,那么在cellForRowAtIndexPath中使用:
[cell clipsToBounds:YES];
#3
1
None of the answer above fully extend the border the entire length of the screen. The only way to achieve this is by pasting the code below in your ViewController:
上面的任何一个答案都不能完全扩展屏幕的整个长度。实现这一点的唯一方法是在你的ViewController中粘贴下面的代码:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
#4
0
Your table view cell is too small. Implement this method in your controller and adjust height for the cell.
您的表视图单元格太小了。在控制器中实现此方法并调整单元格的高度。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60.0;
}
#5
0
In viewDidLoad put:
在viewDidLoad把:
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
#1
11
Go to your table view controller and put these codes into viewDidLoad:
转到您的表视图控制器,将这些代码放入viewDidLoad:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) //should check version to prevent force closed
{
self.tableView.separatorInset = UIEdgeInsetsZero;
}
#2
1
If you don't want to adjust the height of your UITableViewCell
then inside cellForRowAtIndexPath
use:
如果您不想调整UITableViewCell的高度,那么在cellForRowAtIndexPath中使用:
[cell clipsToBounds:YES];
#3
1
None of the answer above fully extend the border the entire length of the screen. The only way to achieve this is by pasting the code below in your ViewController:
上面的任何一个答案都不能完全扩展屏幕的整个长度。实现这一点的唯一方法是在你的ViewController中粘贴下面的代码:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
#4
0
Your table view cell is too small. Implement this method in your controller and adjust height for the cell.
您的表视图单元格太小了。在控制器中实现此方法并调整单元格的高度。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60.0;
}
#5
0
In viewDidLoad put:
在viewDidLoad把:
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];