在我的代码中,我创建了这个
#import <UIKit/UIKit.h>
@interface ViewControllerTable : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (strong, nonatomic) NSString *plcVar;
@end
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
listaPlacas *placas = [[listaPlacas alloc]init];
[self.navigationController pushViewController:placas animated:YES];
}
但在另一种观点中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for (UITableViewCell *cell in [tableView visibleCells]) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
NSString *placaVar = cell.textLabel.text;
ViewControllerTable *VCT = [[ViewControllerTable alloc]init];
VCT.plcVar = [[NSString alloc]init];
VCT.plcVar = placaVar;
}
当我单击后退按钮时,变量 plcVar 中的值为空。