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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:40:22+00:00 2026-06-08T00:40:22+00:00

I’m making my first app and I’m using XCode 4 with a Storyboard. Thanks

  • 0

I’m making my first app and I’m using XCode 4 with a Storyboard. Thanks to this place, lots of tutorials, Apple’s archives databases and a bit of me, I’m slowly getting the basics together. It’s an app populated from a plist. The plist is an array with dictionaries, the dictionarires containing stings with info about different red wines in Norway. First, the plist populates a TableView. I’m using NSSortDescritor to sort the TableView and added a button to the navigation bar for resorting if I want it displayed by another value. It looks like this:

RootTableViewController.h:

#import <UIKit/UIKit.h>

@interface RootTableViewController : UITableViewController <UIActionSheetDelegate> {
NSMutableArray *sortedObjects;
}

-(IBAction)sortButtonPressed:(id)sender;

@end

RootTableViewController.m:

#import "RootTableViewController.h"
#import "ObjectCell.h"
#import "DetailViewController.h"

@interface RootTableViewController ()

@end

@implementation RootTableViewController

- (IBAction)sortButtonPressed:(id)sender;

{
    UIActionSheet *sort = [[UIActionSheet alloc]
   //InitWithStyle etc for sheet
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{
 NSSortDescriptor *sortDesc;

if (buttonIndex == 0) {
        sortDesc = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES];
        [sortedWines sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
        }
if (buttonIndex == 1) {
        sortDesc = [[NSSortDescriptor alloc] initWithKey:@"Country" ascending:YES];
        [sortedWines sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
}
[self.tableView reloadData];
}

- (void)viewDidLoad
{
[super viewDidLoad];

NSString *myfile = [[NSBundle mainBundle]
                    pathForResource:@"Objects" ofType:@"plist"];

sortedObjects = [[NSMutableArray alloc]initWithContentsOfFile:myfile];

NSSortDescriptor * sortDesc = [[NSSortDescriptor alloc] initWithKey:@"Popularity" ascending:YES];
[sortedObjects sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
[super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (void)viewWillAppear:(BOOL)animated {
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [sortedObjects count];
}

//(I’m using a Custom Cell for the TableView)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"objectCell";

    ObjectCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

    cell = [[[ObjectCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }


    cell.nameLabel.text = [[sortedObjects objectAtIndex:indexPath.row] valueForKey:@"Name"];
    cell.countryLabel.text = [[sortedObjects objectAtIndex:indexPath.row] valueForKey:@"Country"];
    return cell;
}

#pragma mark - Table view delegate
//Then the selected object is sent to the DetailViewController in this segue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {


    if ([[segue identifier] isEqualToString:@"DetailSegue"]) {

        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        DetailViewController *detailViewController = [segue destinationViewController];

        detailViewController.selectedObject = [sortedObjects objectAtIndex:selectedRowIndex.row];
    }
}



@end

Then the DetailViewController recieves the selected object to populate the Labels and ImageViews with the data from it.

DetailViewController.h:

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController 

@property (nonatomic, strong) IBOutlet UILabel *districtLabel;
@property (nonatomic, strong) IBOutlet UILabel *countryLabel;
@property (nonatomic, strong) IBOutlet UIImageView *bottleImageView;

@property (nonatomic, strong) NSString *selectedObject;

@end

DetailViewController.m:

#import "WinesDetailViewController.h"

@interface WinesDetailViewController ()

@end

@implementation WinesDetailViewController

@synthesize districtLabel,countryLabel,bottleImageView;

@synthesize selectedObject;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    // Custom initialization
    }
    return self;
}


- (void)viewDidAppear:(BOOL)animated
{
    self.title = [selectedObject valueForKey:@"Name"];
    [super viewDidAppear:animated];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    districtLabel.text = [selectedObject valueForKey:@"District"];
    countryLabel.text = [selectedObject valueForKey:@"Country"];
    bottleImageView.image = [UIImage imageNamed:[selectedObject valueForKey:@"Image"]];

self.navigationController.navigationBar.translucent = YES;
self.wantsFullScreenLayout = YES;

//Then I’ve added recognizers for left and right swiping:

UISwipeGestureRecognizer *leftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDetectedLeft:)];
leftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftGesture];

UISwipeGestureRecognizer *rightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDetectedRight:)];
rightGesture.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightGesture];


}

//And the voids to handle the swipes:

- (void)swipeDetectedRight:(UISwipeGestureRecognizer *)sender
{
//Access previous cell in TableView
}

- (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
{
//Access next cell in TableView
}


//Some more besic code for the view..

@end

As you can see, I’ve added UISwipeGestureRecognizers in the DetailViewController, because I want to reload it with data from the previous cell to when swiped to the right, and next cell when swiped to the left. Now I have no idea how to handle the voids for swipe detected, how can I reach selectedRowIndex from DetailView and swipe through cells? I’m new to programming, have been trying to figure this out for a long time now, so code examples would be great so the answer don’t lead to 100 new questions if you know what I mean. Thank you so much if you can help me.

  • 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-08T00:40:24+00:00Added an answer on June 8, 2026 at 12:40 am

    One way to go about this is to pass the “sorted” datasource array to the DetailViewController and the indexpath through the “prepareForSegue” method.

    RootTableViewController.h:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
    
        if ([[segue identifier] isEqualToString:@"DetailSegue"]) {
    
            NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
            DetailViewController *detailViewController = [segue destinationViewController];
    
            detailViewController.selectedObject = [sortedObjects objectAtIndex:selectedRowIndex.row];
    
            //added code
            detailViewController.detailsDataSource = [[NSArray alloc]initWithArray:sortedObjects];
            detailViewController.detailIndex = selectedRowIndex.row;
        }
    }
    

    Then you could reload the UI elements of the DetailViewController.
    Here is the declaration of the new properties.

    DetailViewController.h:

    #import <UIKit/UIKit.h>
    
    @interface DetailViewController : UIViewController 
    
    @property (nonatomic, strong) IBOutlet UILabel *districtLabel;
    @property (nonatomic, strong) IBOutlet UILabel *countryLabel;
    @property (nonatomic, strong) IBOutlet UIImageView *bottleImageView;
    
    @property (nonatomic, strong) NSString *selectedObject;
    
    // added code
    @property (strong, nonatomic) NSArray *detailsDataSource;
    @property int detailIndex;
    @end
    

    Don’t forget to synthesize the new properties
    @synthesize detailsDataSource,detailIndex;

    //And the voids to handle the swipes:
    
    - (void)swipeDetectedRight:(UISwipeGestureRecognizer *)sender
    {
    //Access previous cell in TableView
        if (detailIndex != 0) // This way it will not go negative
              detailIndex--;  
    
        districtLabel.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"District"]];
        countryLabel.text =  [[detailsDataSource objectAtIndex: detailIndex]  valueForKey:@"Country"];
        bottleImageView.image = [UIImage imageNamed:[[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Image"]];
    }
    
    - (void)swipeDetectedLeft:(UISwipeGestureRecognizer *)sender
    {
    //Access next cell in TableView
        if (detailIndex != [detailsDataSource count]) // make sure that it does not go over the number of objects in the array.
        detailIndex++;  // you'll need to check bounds 
    
        districtLabel.text = [[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"District"]];
        countryLabel.text =  [[detailsDataSource objectAtIndex: detailIndex]  valueForKey:@"Country"];
        bottleImageView.image = [UIImage imageNamed:[[detailsDataSource objectAtIndex: detailIndex] valueForKey:@"Image"]];
    }
    
    
    //Some more besic code for the view..
    
    @end
    

    Give this a try it might work for you. Otherwise, I think you might want to take a look at Scrollview and “paging.” iPhone/iPad users are used to this UI design, and you might be able to modify it to fit what you are doing.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.