This, I think, is the main problem, because stackoverflow is full of it and because of google. But nothing helped me. I need to pass an integer vaule that says which row is selected to another class. Here is my code:
TableViewController.h
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 can I declare my variable 'selectedrow' to use it in FirstViewController?
source share