我的应用程序中有两个 UIView。 在第一个 View 中,有一个带有两个单元格的表格(用于选择城市和国家/地区)。当用户选择第一个单元格(选择城市)时,它会转到另一个包含城市列表的 View 。然后当用户选择一个城市(选择一个 tableviecell 文本)时,所选内容应显示在 firtview 的 tableviewcell 文本中。 这是我在 secondview Controller 中的代码(它是一个 tableview Controller )。
- (void)viewDidLoad {
[super viewDidLoad];
detailFlights = @[@"colombo1",@"colombo2",@"colombo3",@"colombo14",@"colombo15",@"colombo16",@"colombo17"];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [detailFlights count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identi" forIndexPath:indexPath];
cell.textLabel.text = [detailFlights objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
最佳答案
这类问题使用委托(delegate)模式解决。 iOS 编程中广泛使用的一种模式。参见 this question如果您不知道它是如何工作的。
关于ios - 如何将选定的表格 View 单元格文本发送到 iOS 中的上一个 View Controller ,Objective C(向后传递数据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34564388/