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

  • Home
  • SEARCH
  • 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 8743861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:45:06+00:00 2026-06-13T11:45:06+00:00

this is I think basic problem because stackoverflow is full of it and ofc

  • 0

this is I think basic problem because stackoverflow is full of it and ofc google too. But nothing helped me. I need to pass integer vaule which says which row is selected, to another class. Here is my code:

TableViewController.h

#import <UIKit/UIKit.h>

@interface TableViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

{
    NSArray *tabledata;
}
@property (nonatomic, retain) NSArray *tabledata;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic) NSInteger selectedRow;

@end

TableViewController.m

#import "Instruments.h"

@interface Instruments ()

@end

@implementation Instruments
@synthesize tabledata;
@synthesize tableView;
@synthesize selectedRow;

- (void)viewDidLoad
{
    [super viewDidLoad];
    tabledata = [[NSArray alloc] initWithObjects:@"Row1", @"Row2", @"Row3", nil];
    self.selectedRow = 0;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableview cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    cell = [tableview dequeueReusableCellWithIdentifier:@"Row1"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Row1"];
    }

    cell.textLabel.text = [tabledata objectAtIndex:indexPath.row];

    if (indexPath.row == self.selectedRow)
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

- (void)tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row != self.selectedRow) {
        self.selectedRow = indexPath.row;
    }

    [tableView reloadData];
}


- (void)viewDidUnload {
    [self setTableView:nil];
    [super viewDidUnload];
}
@end

FirstViewController.h

//Some code which calls my variable 'selectedrow'
...

FirstViewController.m

...
if selectedrow = 0 {
//some code
}
if selectedrow = 1 {
//some code
}
if selectedrow = 2 {
//some code
}
...

How should I declare my variable ‘selectedrow’ to be able to use it in FirstViewController?

  • 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-13T11:45:07+00:00Added an answer on June 13, 2026 at 11:45 am

    In the MVC world, everything that you intend to share among multiple view controllers belongs in the model. Your model class is globally available; one controller sets the value; the other reads it.

    Header: MyAppModel.h

    @interface MyAppModel // <<<=== Use an appropriate name here
    +(MyAppModel*)instance;
    @property (readwrite) NSInteger selectedRow;
    @end
    

    Implementation: MyAppModel.m

    @implementation MyAppModel
    +(MyAppModel*)instance {
        static MyAppModel *statInst;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            statInst = [[MyAppModel alloc] init];
        });
        return statInst;
    }
    @synthesize selectedRow;
    @end
    

    Usage: your view controllers

    // Set the selected row
    [MyAppModel instance].selectedRow = indexPath.row;
    
    // Access the last selected row
    switch ([MyAppModel instance].selectedRow) {
        case 1: // some code
        break;
        case 2: // some code
        break;
        case 3: // some code
        break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I think this is a pretty basic question on OOP, but unfortunately I wasn't
I think this is a pretty basic question, but after Googling around I can't
I think I have a basic understanding of this, but am hoping that someone
this question may seem too basic to some, but please bear with be, it's
I think the following is a basic problem. I using this number Picker as
I think I'm having a really basic problem here but I can't seem to
I am new to WCF so I think this is pretty basic. I have
I am relatively new to XSL and I think this is a basic question.
I think this could be a very easy question for you. But I have
I have what I THINK is a simple problem here. I'm calling a basic

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.