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 8408861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:44:54+00:00 2026-06-09T23:44:54+00:00

I’m trying to make a scene where the user can swipe over the screen

  • 0

I’m trying to make a scene where the user can swipe over the screen to browse between posts. The post can be both an image with text or just a note, and the view is altered depending on which one occurs.

The getting process works just perfect. It gets the right post whether i swipe right or left. The problem is that the old view wont disappear and the views are overlapping. This is especially bothering when you go from a note to a photo or vice versa since the sizes ar different…

Here’s the code:

- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@" GETRESULT %@   POSTNUMBER %d", getResult, postNumber);
Post *postInfo = [[Post alloc] init];

postInfo = [getResult objectAtIndex:postNumber];

UITextView *postText = [[UITextView alloc] init];
imgView = [[UIImageView alloc] init];

NSString *getImageString = postInfo.attachments;
if(getImageString){
    postText = [[UITextView alloc] init];
    postText.text = postInfo.noteText;
    [postText setFrame:CGRectMake(20, 320, 280, 80)];
    NSLog(@"IMG1");
}else {
    postText = [[UITextView alloc] init];
    postText.text = postInfo.noteText;
    [postText setFrame:CGRectMake(20, 10, 280, 240)];
    NSLog(@"TEXT1");
}
[self.view addSubview:postText];
SHOWHUD(self.view);
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

        NSURL *url = [NSURL URLWithString:getImageString];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *img = [[UIImage alloc] initWithData:data];
        [imgView setFrame:CGRectMake(20, 10, 280, 300)];
        [imgView setContentMode:UIViewContentModeScaleAspectFit];
        [imgView setImage:img];

    dispatch_async(dispatch_get_main_queue(), ^{   
        [self.view addSubview:imgView];
        HIDEHUD(self.view);
    });
});


UISwipeGestureRecognizer *recognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
[[self view] addGestureRecognizer:recognizerRight];

UISwipeGestureRecognizer *recognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)];
[recognizerLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:recognizerLeft];

// Do any additional setup after loading the view.
}

- (void)handleSwipeRight:(UISwipeGestureRecognizer *)gestureRecognizer{
NSLog(@"SWIPE RIGHT");
if(postNumber > 0){
    postNumber--;
    Post *postInfo = [[Post alloc] init];

    postInfo = [getResult objectAtIndex:postNumber];

    UITextView *postText = [[UITextView alloc] init];
    imgView = [[UIImageView alloc] init];

    NSString *getImageString = postInfo.attachments;
    if(getImageString){
        [postText removeFromSuperview];
        postText = [[UITextView alloc] init];
        postText.text = postInfo.noteText;
        [postText setFrame:CGRectMake(20, 320, 280, 80)];
        NSLog(@"IMG1");
    }else {
        [postText removeFromSuperview];
        postText = [[UITextView alloc] init];
        postText.text = postInfo.noteText;
        [postText setFrame:CGRectMake(20, 10, 280, 240)];
        NSLog(@"TEXT1");
    }
    [self.view addSubview:postText];
    SHOWHUD(self.view);
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        if (getImageString) {

        NSURL *url = [NSURL URLWithString:getImageString];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *img = [[UIImage alloc] initWithData:data];
        [imgView setFrame:CGRectMake(20, 10, 280, 300)];
        [imgView setContentMode:UIViewContentModeScaleAspectFit];
        [imgView setImage:img];
        }else {
            [imgView removeFromSuperview];
        }
        dispatch_async(dispatch_get_main_queue(), ^{   
            [self.view addSubview:imgView];
            HIDEHUD(self.view);
        });
    });
}

}

- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer{
NSLog(@"SWIPE LEFT");
if(postNumber < [getResult count] - 1){
    postNumber++;

    Post *postInfo = [[Post alloc] init];

    postInfo = [getResult objectAtIndex:postNumber];

    UITextView *postText = [[UITextView alloc] init];
    imgView = [[UIImageView alloc] init];

    NSString *getImageString = postInfo.attachments;
    if(getImageString){
        [postText removeFromSuperview];
        postText = [[UITextView alloc] init];
        postText.text = postInfo.noteText;
        [postText setFrame:CGRectMake(20, 320, 280, 80)];
        NSLog(@"IMG1");
    }else {
        [postText removeFromSuperview];
        postText = [[UITextView alloc] init];
        postText.text = postInfo.noteText;
        [postText setFrame:CGRectMake(20, 10, 280, 240)];
        NSLog(@"TEXT1");
    }
    [self.view addSubview:postText];
    SHOWHUD(self.view);
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        if(getImageString){
        NSURL *url = [NSURL URLWithString:getImageString];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *img = [[UIImage alloc] initWithData:data];
        [imgView setFrame:CGRectMake(20, 10, 280, 300)];
        [imgView setContentMode:UIViewContentModeScaleAspectFit];
        [imgView setImage:img];
        }else {
            [imgView removeFromSuperview];
        }
        dispatch_async(dispatch_get_main_queue(), ^{   
            [self.view addSubview:imgView];
            HIDEHUD(self.view);
        });
    });

}
}

At first i only increased postNumber and called viewDidLoad in the swipe actions. That gave me the exact same result though… This is only one of countless trial and error attempts, and I’m sorry this is among the messier ones…

Would greatly appreciate it if anyone got a solution.

Thanks in advance,
Tom

  • 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-06-09T23:44:56+00:00Added an answer on June 9, 2026 at 11:44 pm

    I couldn’t remove the variables from the superview because I did it in a new instance of viewDidLoad. I tried to do so before calling viewDidLoad this time and it worked!

    Sorry for wasting your time…

    Tom

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.