gpt4 book ai didi

ios - 数据未传输到下一个 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:35 24 4
gpt4 key购买 nike

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSLog((@"This is didSelectRowAtIndexPAth"));
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.myDictionary = [self.placeArray objectAtIndex:[indexPath row]];

/* The below NSlog is showing the content , its not null still in next viewcontroller same variable showing null content*/

NSLog(@"My Dictionary: This is a MasterView%@",detailViewController.myDictionary);
[self performSegueWithIdentifier:@"showDetail" sender:self];
}

最佳答案

这是因为您的 DetailViewController 实例与您手动创建的实例不同。您应该自己呈现新的 ViewController(模态或通过推送),或者实现 prepareForSegue 方法并在那里设置字典。

编辑:

两种解决方案:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.myDictionary = [self.placeArray objectAtIndex:[indexPath row]];

// If it is a modal
[self presentViewController:detailViewController animated:YES];
}

@implementation MyClass {
NSIndexPath *selectedCellIndexPath;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSLog((@"This is didSelectRowAtIndexPAth"));
selectedCellIndexPath = indexPath;

[self performSegueWithIdentifier:@"showDetail" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
DetailViewController *detailViewController = (DetailViewController *)segue.destinationViewController;
detailViewController.myDictionary = [self.placeArray objectAtIndex:selectedCellIndexPath.row];
}
}

关于ios - 数据未传输到下一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19902102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com