Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4602256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:57:20+00:00 2026-05-21T23:57:20+00:00

hopefully someone will be able to help me. I have a UIScrollView on my

  • 0

hopefully someone will be able to help me. I have a UIScrollView on my page. The .h file has set the UIscrollviewdelegate.

I have a class file called “Picture.h / Picture.m”.

- (id)initWithName:(NSString *)aName filename:(NSString *)aFilename {
    self.name = aName;
    self.filename = aFilename;
    return self; 
}

In this class file, I simply set a couple of strings. I load an array with object of this picture class, for example

Picture *image2 = [[Picture alloc] initWithName:@"Apple" filename:@"apple.png"];
[pictureArray addObject: image2];
[image2 release];

Within my viewController, I call this class and assign is as such

Picture *thisPicture = (Picture *)[appDelegate.pictureArray objectAtIndex:0];
view2image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", thisPicture.filename]];

The above works fine. The image is set to what ever I put, example, “apple.png”. However, when I tried to set this in the - (void) scrollViewDidScroll:(UIScrollView *) method within my viewController, I get a bad exec error and the app crashes.

Yet, if I had an array of filenames (so not storing my class object in the array) and access objectAtIndex:0 in the scrollViewDidScroll – it works fine.

So, this code is OK

nextImageView.image = [UIImage imageNamed: [NSString stringWithFormat:@"%@", [appDelegate.pictureCardsArray objectAtIndex:0]]];

but this crashes

Picture *image3 = (Picture *)[appDelegate.pictureArray objectAtIndex:0];
nextImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", image3.filename]];

Interestingly though, if I don’t try to access the element of image3 (eg image3.filename) it doesn’t crash. This is useless though! Also, if I disable the delegate = self for the uiscrollview, then this code works, but none of the scrolling actions are fired. I came across this post (http://stackoverflow.com/questions/1734720/uiscrollview-on-a-uiviewcontroller) when searching for the solution, but cannot see where I might be releasing the viewController early. To be safe, nothing is getting released (yet!)

Hopefully someone might be able to shed some light on it!!

[edit]Just adding in the full class files][/edit]

Picture.h

#import <UIKit/UIKit.h>

@interface Picture : NSObject {
    NSString *name;
    NSString *filename;
}

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *filename;

- (id)initWithName:(NSString *)aName filename:(NSString *)aFilename;

@end

Picture.m

#import "Picture.h"

@implementation Picture
@synthesize name, filename;

- (id)initWithName:(NSString *)aName filename:(NSString *)aFilename {

    self.name = aName;
    self.filename = aFilename;
    return self;

}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:57:20+00:00Added an answer on May 21, 2026 at 11:57 pm

    Just for completeness… the solution was as Antwen Van Houdt said – I changed copy to retain and it worked fine.

    #import <UIKit/UIKit.h>
    
    @interface Picture : NSObject {
        NSString *name;
        NSString *filename;
    }
    
    @property (nonatomic, retain) NSString *name;
    @property (nonatomic, retain) NSString *filename;
    
    - (id)initWithName:(NSString *)aName filename:(NSString *)aFilename;
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully someone will be able to help me with this! I'm trying to get
Hopefully someone here can help me with this challenge! I have a parent page
Hopefully someone can explain some behavior to me. I have a JSF page with
Hopefully someone will be able to point me in the right direction - I
This could be a very basic question, but hopefully someone will be able to
I don't even know if this is possible but hopefully someone will be able
Hopefully someone can help with this, I can't find the answer anywhere! I'm currently
Quick question hopefully someone can help out here. I'm trying to copy and paste
i got problem with my code and hopefully someone able to figure it out.
I'm out of ideas and have been searching for awhile now, so hopefully someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.