How to access a selection of a subset of UITableView?

I created UIViewController( AnestDrugCalcViewController) which has a button that opens UITableViewController( DrugTableViewController) to select the medicine. DrugTableViewControllerIt is filled on the basis NSMutableArrayand consists of several objects NSDictionary(drugName, drugDose, drugConcentration, etc.).

I can open DrugTableViewControllerit by clicking on the navigation stack, but I can’t figure out how to say from mine AnestDrugCalcViewControllerthat the properties of the selected item.

//  DrugTableViewController.h
#import <UIKit/UIKit.h>

@interface DrugTableViewController : UITableViewController {
NSMutableArray          *drugList;
NSIndexPath *lastIndexPath;
IBOutlet UITableView    *myTableView;
NSObject *selectedDrug;
}

@property (nonatomic, retain) NSArray *drugList;
@property (nonatomic, retain) UITableView *myTableView;
@property (nonatomic, retain) NSObject *selectedDrug;

@end

Top of DrugTableViewController.m #import "DrugTableViewController.h"

@implementation DrugTableViewController

@synthesize drugList,myTableView, selectedDrug; 
+3
source share
2 answers

vwDrugTable, , . , , vwCalc, .

, vwDrugTable - :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.selectedDrug = [self.drugs objectAtIndex:indexPath.row];
}

selectedDrug vwCalc, .

+3

UITableView -indexPathForSelectedRow , :

NSIndexPath *selectionPath = [vwDrugTable indexPathForSelectedRow];
if (index) {
    NSLog(@"Selected row:%u in section:%u", [selectionPath row], [selectionPath section]);
} else {
    NSLog(@"No selection");
}

, tableView:didSelectRowAtIndexPath: :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Selection Changed");
}
+3

Source: https://habr.com/ru/post/1708289/


All Articles