【发布时间】:2017-01-10 08:20:37
【问题描述】:
尝试将数据从 tableviewcontroller 传回 viewcontroller 时的一个小问题。我在视图控制器中有 3 个按钮和 3 个文本字段,当单击每个按钮时,将导航到具有静态数据(如头痛、发烧、咳嗽、感冒)的同一个表格视图。当我在表格视图中选择一行时,问题就来了当我选择 Cough 时单击它应该只分配给第二个文本文件。下面是我的代码。
In **AppDelegate.h**
@property (strong, nonatomic) NSString *selectedText;
In **ViewController.m**
-(void)viewWillAppear:(BOOL)animated
{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
txtField1.text = appDelegate.selectedText;
txtField2.text = appDelegate.selectedText;
txtField3.text = appDelegate.selectedText;
}
**FamilyDetailsViewController.m**
pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selected= [arr objectAtIndex:indexPath.row];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.selectedText = selected;
[self.navigationController popViewControllerAnimated:YES];
}
【问题讨论】:
-
它清楚地表明您正在将 selectedText 分配给 3 文本字段。没有您分配文本的条件
标签: ios objective-c iphone xcode uitableview