我创建了一个 UIViewController
(AnestDrugCalcViewController
),它有一个按钮可以打开 UITableViewController
(DrugTableViewController
) 选择药物。 DrugTableViewController
基于 NSMutableArray
进行填充,并由多个 NSDictionary
对象(drugName、drugDose、drugConcentration 等)组成。
我可以通过将 DrugTableViewController
插入导航堆栈来打开它,但我不知道如何从我的 AnestDrugCalcViewController
中判断所选项目是。
// 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
DrugTableViewController.m 的顶部 #import "DrugTableViewController.h"
@implementation DrugTableViewController
@synthesize drugList,myTableView, selectedDrug;
最佳答案
您可以在 vwDrugTable
中拥有一个属性,用于在用户选择时存储所选行。然后,在删除该 TableView 并返回到 vwCalc
后,只需从该属性中获取数据即可。
所以这意味着在 vwDrugTable
中,有这样的东西:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedDrug = [self.drugs objectAtIndex:indexPath.row];
}
然后在需要时从 vwCalc
访问 selectedDrug
。
关于iphone - 如何访问 UITableView subview 选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/860196/