سؤال

أواجه بعض المشاكل مع الرسوم المتحركة UiimageView. لقد قمت بإنشاء ثلاثة كائنات NSArray التي تحتوي على الصور وإنشاء ثلاث طرق تأخذ uiimageView وتعيين الرسوم المتحركة الجديدة إليها. إنه يعمل بشكل رائع يدعو أحد الأساليب الثلاث في المرة الأولى ولكن القيام بذلك في وقت آخر تعطل محاكاة وجهاز. أيه أفكار؟

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

// set the anims
slowAnimation = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"image1.jpg"],
                    [UIImage imageNamed:@"image2.jpg"],
                                nil];
defaultAnimation = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"image3.jpg"],
                    [UIImage imageNamed:@"image4.jpg"],
                        nil];
fastAnimation = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"image5.jpg"],
                    [UIImage imageNamed:@"image6.jpg"],
                    nil];

// load the default speed - this works once, but when applied a second time it crashes the simulator and device
[self setDefaultAnim:myUIImageViewObject];

[super viewDidLoad];
}


// animation switcher
-(void)setSlowAnim:(UIImageView *)imageView
{
    [imageView stopAnimating];
    imageView.animationImages = slowAnimation;
    imageView.animationDuration = 0.4;
    [imageView startAnimating];
}
-(void)setDefaultAnim:(UIImageView *)imageView
{
    [imageView stopAnimating];
    imageView.animationImages = defaultAnimation;
    imageView.animationDuration = 0.4;
        [imageView startAnimating];
}
-(void)setFastAnim:(UIImageView *)imageView
{
    [imageView stopAnimating];
    imageView.animationImages = fastAnimation;
    imageView.animationDuration = 0.4;
   [imageView startAnimating];
}

خطأ في السجل:

[Session started at 2009-04-06 22:46:54 +0100.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols for "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics" (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/hello/Library/Application Support/iPhone Simulator/User/Applications/6DB7C45D-1A26-4775-9AE3-C30F3EBC9F83/PlateSpinner.app/PlateSpinner', process 345.
kill
quit

The Debugger has exited with status 0.
هل كانت مفيدة؟

المحلول

أعتقد أنك بحاجة إلى retain الصفائف الثلاثة التي تنشئها viewDidLoad - أنت لا تتصل أبدا alloc عليهم، لذلك ليس لديك ملكية حتى تتصل retain.

نصائح أخرى

بدلا من مجرد الاتصال بالاحتفاظ باستخدام رسالة initwithobjects:

slowAnimation = [[NSArray alloc] initWithObjects:
                                  [UIImage imageNamed:@"image1.jpg"],
                                  [UIImage imageNamed:@"image2.jpg"],
                                  nil];

إذا كنت تفعل الأسطوانة التي تشير إليها، رغم ذلك، لاحظ أنك ستحتاج إلى إطلاق كائن البطيء لاحقا. نظرا لأنك Alloc'd، فسيحصل على عدد محافظات من 1 حتى يخبر شخص ما عن وقت التشغيل بطريقة أخرى.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top