试图显示图像的数组,code返回的iPhone主屏幕 [英] Trying to display array of images, code returns iphone to home screen

查看:163
本文介绍了试图显示图像的数组,code返回的iPhone主屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的问题是code:

的code是显示图像的阵列,然后可以通过滚动

   - (无效)viewDidLoad中{
    [超级viewDidLoad中];    NSArray的*照片= [[NSArray的arrayWithObjects:
                        [UIImage的imageNamed:@Event.png],
                        [UIImage的imageNamed:@为Logo.png],
                        [UIImage的imageNamed:@为Default.png],
                        [UIImage的imageNamed:@LittleLogoImage.png],
                        零]保留] // TODO - 填写您的照片    //注意,视图包含aScrollView一个UIScrollView    INT I = 0;
    INT宽度= 0;
    INT高度= 0;
    对于(的NSString *的照片图像)
    {
        * UIImage的图像= [UIImage的imageNamed:[组图objectAtIndex:我]];
        * UIImageView的ImageView的= [[UIImageView的页头] initWithImage:图片];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.clipsToBounds = YES;        imageView.frame = CGRectMake(imageView.frame.size.width * I + +,0,imageView.frame.size.width,imageView.frame.size.height);        [aScrollView addSubview:ImageView的]。
        宽度= imageView.frame.size.width;
        高度= imageView.frame.size.height;        [ImageView的释放];
    }
    aScrollView.contentSize = CGSizeMake(宽*我,高度);
    aScrollView.delegate =自我;
}

任何想法?


  

[会话开始于2011-05-07
  22时46分47秒+0100] 2011-05-07
  22:46:49.314 ALPHA [1171:207] load01
  2011-05-07 22:47:13.749
  ALPHA [1171:207] 2 2011-05-07
  22:47:13.751 ALPHA [1171:207] dealloc01
  2011-05-07 22:47:13.755
  ALPHA [1171:207] load02 2011-05-07
  22:47:19.791 ALPHA [1171:207] 4
  2011-05-07 22:47:19.792
  ALPHA [1171:207] dealloc02 2011-05-07
  22:47:19.795 ALPHA [1171:207] - [UIImage的
  长]:无法识别的选择发送到
  例如0x4b20f60​​ 2011-05-07
  22:47:19.797 ALPHA [1171:207] *
  终止应用程序由于未捕获
  例外
  NSInvalidArgumentException'的,究其原因:
  ' - [UIImage的长度]:无法识别
  选择发送到实例0x4b20f60​​
  *
是在第一掷调用堆栈:(0的CoreFoundation结果
  0x00dca5a9 例外preprocess + 185
    1 libobjc.A.dylib结果
  0x00f1e313 objc_exception_throw + 44
    2的CoreFoundation结果
  0x00dcc0bb - [NSObject的(NSObject的)
  doesNotRecognizeSelector:] + 187 3结果
  的CoreFoundation结果
  0x00d3b966 __ 转发
+ 966 4结果
  的CoreFoundation结果
  0x00d3b522 _CF_forwarding_ prep_0 + 50
    5 UIKit的结果
  0x003e3568 _UIImageAtPath + 36 6结果
  ALPHA结果
  0x000037fd - [PhotosView viewDidLoad中] +
  597 7 UIKit的结果
  0x0036a089 - [UIViewController中查看] +
  179 8 ALPHA结果
  0x00002af3 - [ALPHAViewController
  displayView:] + 500 9 ALPHA结果
  0x00002707 - [ALPHAAppDelegate
  displayView:] + 60 10 ALPHA结果
  0x00002cdd - [视图2 viewPhotos:] + 99
    11 UIKit的结果
  0x002ba4fd - [UIApplication的
  sendAction::从:forEvent:] + 119
    12 UIKit的结果
  0x0034a799 - [UIControl
  sendAction:到:forEvent:] + 67 13
  UIKit的结果
  0x0034cc2b - [UIControl(内部)
  _sendActionsForEvents:withEvent:方法] + 527 14 UIKit的结果
  0x0034b7d8 - [UIControl
  touchesEnded:withEvent:方法] + 458 15
  UIKit的结果
  0x002deded - [的UIWindow
  _sendTouchesForEvent:] + 567 16 UIKit的结果
  0x002bfc37 - [UIApplication的的SendEvent:]
  + 447 17 UIKit的0x002c4f2e _UIApplicationHandleEvent +
  7576 18 GraphicsServices结果
  0x01722992 PurpleEventCallback + 1550
    19的CoreFoundation结果
  0x00dab944
   CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
  + 52 20的CoreFoundation 0x00d0bcf7 __CFRunLoopDoSource1 + 215
    21的CoreFoundation结果
  0x00d08f83 __CFRunLoopRun + 979 22
  的CoreFoundation结果
  0x00d08840 CFRunLoopRunSpecific + 208
    23的CoreFoundation结果
  0x00d08761 CFRunLoopRunInMode + 97 24
  GraphicsServices结果
  0x017211c4 GSEventRunModal + 217 25
  GraphicsServices结果
  0x01721289 GSEventRun + 115 26的UIKit
  0x002c8c93 UIApplicationMain + 1160
    27 ALPHA结果
  0x000026a8主+ 102 28 ALPHA结果
  0x00002639启动+ 53)


抛出NSException

的实例后终止叫

再次感谢,

杰克


解决方案

 为(* NSString的照片图像)
{
    * UIImage的图像= [UIImage的imageNamed:[组图objectAtIndex:我]];
    ...

这是你的问题。你有一个的NSString 的UIImage 命名为同样的事情。当你重新定义你的的NSString 的UIImage ,你是在混淆的 forin 循环。循环似乎仍然认为你有一个的NSString ,当在现实中,你有一个的UIImage 。因此,我们的第一步是尝试与此code而不是替换code:

 为(* NSString的在imageName照片)
{
    * UIImage的图像= [UIImage的imageNamed:imageName];
    ...

不过,code将不能工作。幸运的是,你的图片数组已经存储 UIImages ,所以你不需要的NSString 在所有!因此,你可以用这个代替的前三行的循环:

 为(* UIImage的照片图像)
{
    ...

这就是它!你并不需要你的的UIImage *图像= ... 行,因为在所有它的括号创建。

希望这有助于!

Here is the problem code:

The code is to display an array of images which can then be scrolled through.

- (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *photos = [[NSArray arrayWithObjects:   
                        [UIImage imageNamed:@"Event.png"],
                        [UIImage imageNamed:@"Logo.png"],
                        [UIImage imageNamed:@"default.png"],
                        [UIImage imageNamed:@"LittleLogoImage.png"],
                        nil] retain];      // TODO – fill with your photos

    // note that the view contains a UIScrollView in aScrollView

    int i=0;
    int width = 0;
    int height = 0;
    for ( NSString *image in photos )
    {
        UIImage *image = [UIImage imageNamed:[photos objectAtIndex:i]];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.clipsToBounds = YES;

        imageView.frame = CGRectMake( imageView.frame.size.width * i++, 0, imageView.frame.size.width, imageView.frame.size.height);

        [aScrollView addSubview:imageView];
        width = imageView.frame.size.width;
        height = imageView.frame.size.height;

        [imageView release];
    }
    aScrollView.contentSize = CGSizeMake(width*i, height);
    aScrollView.delegate = self;
}

Any ideas?

[Session started at 2011-05-07 22:46:47 +0100.] 2011-05-07 22:46:49.314 ALPHA[1171:207] load01 2011-05-07 22:47:13.749 ALPHA[1171:207] 2 2011-05-07 22:47:13.751 ALPHA[1171:207] dealloc01 2011-05-07 22:47:13.755 ALPHA[1171:207] load02 2011-05-07 22:47:19.791 ALPHA[1171:207] 4 2011-05-07 22:47:19.792 ALPHA[1171:207] dealloc02 2011-05-07 22:47:19.795 ALPHA[1171:207] -[UIImage length]: unrecognized selector sent to instance 0x4b20f60 2011-05-07 22:47:19.797 ALPHA[1171:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x4b20f60' * Call stack at first throw: ( 0 CoreFoundation
0x00dca5a9 exceptionPreprocess + 185 1 libobjc.A.dylib
0x00f1e313 objc_exception_throw + 44 2 CoreFoundation
0x00dcc0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3
CoreFoundation
0x00d3b966 __forwarding
+ 966 4
CoreFoundation
0x00d3b522 _CF_forwarding_prep_0 + 50 5 UIKit
0x003e3568 _UIImageAtPath + 36 6
ALPHA
0x000037fd -[PhotosView viewDidLoad] + 597 7 UIKit
0x0036a089 -[UIViewController view] + 179 8 ALPHA
0x00002af3 -[ALPHAViewController displayView:] + 500 9 ALPHA
0x00002707 -[ALPHAAppDelegate displayView:] + 60 10 ALPHA
0x00002cdd -[View2 viewPhotos:] + 99 11 UIKit
0x002ba4fd -[UIApplication sendAction:to:from:forEvent:] + 119 12 UIKit
0x0034a799 -[UIControl sendAction:to:forEvent:] + 67 13 UIKit
0x0034cc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 14 UIKit
0x0034b7d8 -[UIControl touchesEnded:withEvent:] + 458 15 UIKit
0x002deded -[UIWindow _sendTouchesForEvent:] + 567 16 UIKit
0x002bfc37 -[UIApplication sendEvent:] + 447 17 UIKit 0x002c4f2e _UIApplicationHandleEvent + 7576 18 GraphicsServices
0x01722992 PurpleEventCallback + 1550 19 CoreFoundation
0x00dab944 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52 20 CoreFoundation 0x00d0bcf7 __CFRunLoopDoSource1 + 215 21 CoreFoundation
0x00d08f83 __CFRunLoopRun + 979 22 CoreFoundation
0x00d08840 CFRunLoopRunSpecific + 208 23 CoreFoundation
0x00d08761 CFRunLoopRunInMode + 97 24 GraphicsServices
0x017211c4 GSEventRunModal + 217 25 GraphicsServices
0x01721289 GSEventRun + 115 26 UIKit 0x002c8c93 UIApplicationMain + 1160 27 ALPHA
0x000026a8 main + 102 28 ALPHA
0x00002639 start + 53 )

terminate called after throwing an instance of 'NSException'

Thanks again,

Jack

解决方案

for ( NSString *image in photos )
{
    UIImage *image = [UIImage imageNamed:[photos objectAtIndex:i]];
    ...

This is your problem. You have an NSString and a UIImage named the same thing. When you redeclare your NSString as a UIImage, you are confusing your the forin loop. The loop seems to still think that you have an NSString, when in reality, you have a UIImage. So our first step is to try replacing that code with this code instead:

for ( NSString *imageName in photos )
{
    UIImage *image = [UIImage imageNamed:imageName];
    ...

However, that code won't work either. Fortunately, your images array already stores UIImages, so your don't need an NSString at all! Thus you can replace the first three lines of your loop with this:

for ( UIImage *image in photos )
{
    ...

That's it! You don't need your UIImage *image = ... line at all since it's created in the parentheses.

Hope this helps!

这篇关于试图显示图像的数组,code返回的iPhone主屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆