我有这个相对简单的辅助方法:
- (float)imageHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
float imageWidth = [[self.widthArray objectAtIndex:indexPath.row] floatValue];
float ratio = screenWidth/imageWidth;
float imageHeight = ratio * [[self.heightArray objectAtIndex:indexPath.row] floatValue];
return imageHeight;
}
- (UIImage *)imageWithImage:(UIImage *)image forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat newWidth = screenRect.size.width;
CGFloat newHeight = [self imageHeightForRowAtIndexPath:indexPath.row];
UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight ));
[image drawInRect:CGRectMake(0, 0, newWidth, newHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Implicit conversion from 'NSInteger' to 'NSIndexPath' is disallowed
最佳答案
您有2种方法:
- (float)imageHeightForRowAtIndexPath:(NSIndexPath *)indexPath
- (UIImage *)imageWithImage:(UIImage *)image forRowAtIndexPath:(NSIndexPath *)indexPath
NSIndexPath *
参数。imageWithImage:forRowAtIndexPath:
中,您正在调用imageHeightForRowAtIndexPath:
:[self imageHeightForRowAtIndexPath:indexPath.row]
row
(一个indexPath
)中获取NSInteger
,并尝试将其传递给imageHeightForRowAtIndexPath:
:,后者需要一个NSIndexPath *
。NSIndexPath *
并且知道您正在提供NSInteger
。CGFloat newHeight = [self imageHeightForRowAtIndexPath:indexPath];
https://stackoverflow.com/questions/27766339/
相关文章:
caching - 如何处理并发Web用户的重置CS-Script
macos - AudioFileReadPackets错误-50
compiler-errors - 如何解决MiniZinc错误: “model inconsist
compilation - 如何在Windows上的SCons中导出具有备用扩展名的程序
actionscript-3 - for(const i)而不是(var i)
android - Android Delphi xe7中的错误
compiler-errors - Latex中缺少\begin {document}