iphone - 如何访问 UITableView subview 选择?

标签 iphone objective-c cocoa-touch uitableview

我创建了一个 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/

相关文章:

iphone - UIButton 的响应时间

ios - 属性 setter 和 getter 无法覆盖

ios - 打开 UILocalNotification 后执行代码

iphone - 自定义 UIView 看起来不像预期的那样

ios - 在 iOS 中查看层次结构

objective-c - 如何在 Objective C 的 typedef 枚举中添加新的枚举?

iphone - 从 web View 中的有序列表中删除缩进

iphone - UIVIewController 自定义初始化方法

ios - MBProgressHUD 不显示

iphone - 将 Xcode 的目标设置为 iPhone 而不是 iPad