具有不同名称的 NSMutableArray 和 SetImage 的相同算法的工作方式不同

Same algorithms with NSMutableArray and SetImage with different names work differently

提问人:Alex Leu 提问时间:5/24/2014 最后编辑:user1118321Alex Leu 更新时间:5/24/2014 访问量:81

问:

所以我有一个问题。

我有:

NSMutableArray *photos_imagesArray;
NSMutableArray *myPhotos_imagesArray;

在 的 .h 文件中声明。@interface EXViewController

我所做的是:

对于一个视图 - - 我从这个视图上获取图像数据并使用 setImage。一切正常。photos_viewControllerphotos_imagesArrayUIImageView

现在,当我做同样的事情时,但使用 和 - setImage 不会启动并被清空。myPhotos_viewControllermyPhotos_imagesArraymyPhotos_imagesArray

为什么会这样工作?我有两个非常相同的算法在两个以及相同的视图中工作,但我得到的结果不同。唯一不同的是几个名字。XCode 甚至没有向我显示任何错误。

更新 1(共享代码):

在 EXViewController.h 中,我声明可变数组的位置。

@interface EXViewController : UIViewController <UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
    UIImagePickerController *upload_imagePickerCamera;
    UIImagePickerController *upload_imagePickerLibrary;
    UIImage *upload_imageUploaded;
    IBOutlet UIImageView *upload_imageViewUploadedImage;

    // Photos Currently viewed
    NSInteger _photoIndex;
    NSMutableArray *photos_imagesArray;
    NSMutableArray *myPhotos_imagesArray;
}

其功能包括:

对于有效的部分 -

// PHOTOS

-(void)goToPhotos {

    [photos_imagesArray removeAllObjects];

    _photoIndex = 0;

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *viewControllerPhotos = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewControllerPhotos"];
    [self  presentViewController:viewControllerPhotos animated:true completion:nil];

    PFQuery *query_photos = [PFQuery queryWithClassName:@"Photo"];
    [query_photos orderByDescending:@"createdAt"];
    [query_photos findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // Copy objects array to photos array
            photos_imagesArray = [objects mutableCopy];

            // Set Current photo
            [self photos_setCurrentPhoto];


        } else {

            NSString *errorString = [error userInfo][@"error"];
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];

        }
    }];
}

-(void)photos_setCurrentPhoto{

    if ([photos_imagesArray count] != 0) {

    PFFile *userImageFile = photos_imagesArray[_photoIndex][@"imageFile"];
    [userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
        if (!error) {
            UIImage *image = [UIImage imageWithData:imageData];
            [self.photos_imageViewCurrent setImage:image];
        }
    }];

    }
}

而对于没有的部分——

// MY PHOTOS

-(void)myPhotos_goToMyPhotos{

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *viewControllerPhotos = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewControllerMyPhotos"];
    [self  presentViewController:viewControllerPhotos animated:true completion:^{

        PFQuery *query_photos = [PFQuery queryWithClassName:@"Photo"];

        [query_photos whereKey:@"userId" equalTo:[PFUser currentUser].objectId];
        [query_photos orderByDescending:@"createdAt"];

        [query_photos findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
                _photoIndex = 0;

                // Copy objects array to photos array
                myPhotos_imagesArray = [objects mutableCopy];

                NSLog(@"%i",[myPhotos_imagesArray count]);

                // Set Current photo
                [self myPhotos_setCurrentPhoto];


            } else {

                NSString *errorString = [error userInfo][@"error"];
                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alert show];

            }
        }];

    }];

}

-(void)myPhotos_setCurrentPhoto{

    if ([myPhotos_imagesArray count] != 0) {

        // Set photo in image view
        PFFile *userImageFile = myPhotos_imagesArray[_photoIndex][@"imageFile"];
        [userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
            if (!error) {
                UIImage *image = [UIImage imageWithData:imageData];
                self.myPhotos_imageViewCurrentPhoto.image = image;
            }
        }];

    }
}

PS 我在完成回调内部和外部尝试了该算法 - 相同的结果。

更新 2(添加了整个 EXViewController.h 文件):

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface EXViewController : UIViewController <UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
    UIImagePickerController *upload_imagePickerCamera;
    UIImagePickerController *upload_imagePickerLibrary;
    UIImage *upload_imageUploaded;
    IBOutlet UIImageView *upload_imageViewUploadedImage;

    // Photo Currently viewed
    NSInteger _photoIndex;
    NSMutableArray *photos_imagesArray;
    NSMutableArray *myPhotos_imagesArray;
}

// Login Form
@property (strong, nonatomic) IBOutlet UITextField *login_fieldEmail;
@property (strong, nonatomic) IBOutlet UITextField *login_fieldPassword;
- (IBAction)login_buttonSignInAction:(id)sender;
- (IBAction)login_buttonForgotAction:(id)sender;


// Sign Up Form
@property (strong, nonatomic) IBOutlet UITextField *signup_fieldEmail;
@property (strong, nonatomic) IBOutlet UITextField *signup_fieldPassword;
@property (strong, nonatomic) IBOutlet UITextField *signup_fieldCountry;
@property (strong, nonatomic) IBOutlet UISegmentedControl *signup_fieldSex;
@property (strong, nonatomic) IBOutlet UITextField *signup_fieldYear;
- (IBAction)buttonSignupAction:(id)sender;

// Photos
@property (weak, nonatomic) IBOutlet UIImageView *photos_imageViewCurrent;
- (IBAction)photos_buttonRatePlus:(id)sender;
- (IBAction)photos_buttonRateMinus:(id)sender;


// Menu
- (IBAction)menu_buttonSignOutAction:(id)sender;
- (IBAction)menu_buttonMyPhotos:(id)sender;


// Upload Photo
- (IBAction)upload_buttonTakePhoto:(id)sender;
- (IBAction)upload_buttonPhotoAlbum:(id)sender;
- (IBAction)upload_buttonUpload:(id)sender;
@property (strong, nonatomic) IBOutlet UIProgressView *upload_progressViewUpload;
@property (strong, nonatomic) IBOutlet UILabel *upload_labelImageUploaded;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *upload_gravity;

// My Photos
@property (weak, nonatomic) IBOutlet UIImageView *myPhotos_imageViewCurrentPhoto;
@property (weak, nonatomic) IBOutlet UILabel *myPhotos_labelRating;
@property (weak, nonatomic) IBOutlet UILabel *myPhotos_labelVotes;
- (IBAction)myPhotos_buttonNext:(id)sender;
- (IBAction)myPhotos_buttonPrevious:(id)sender;



@end
目标-C 阵 列 nsmutable数组 可变

评论

0赞 zaph 5/24/2014
显然,这与名字无关。使它们成为属性并在其上设置断点,以便您查看正在发生或未发生的情况。或者只是在所有行上放置断点,以更改和访问无法正常工作的行。
0赞 nielsbot 5/24/2014
没有更多信息很难说。您应该添加一些断点并登录代码以检查您的假设。
1赞 Hermann Klecker 5/24/2014
请分享一些代码。
0赞 rdelmar 5/24/2014
您在 EXViewController 中发布的所有代码都包含在 EXViewController 中吗?
0赞 stevesliva 5/24/2014
FWIW,您的 setImage 语法在两者之间是不同的。我看不出这有什么关系,除非块由于语法不同而保留不同的指针。

答: 暂无答案