gpt4 book ai didi

ios - 将 TableView 部分标题传递给另一个 View 的导航栏标题

转载 作者:行者123 更新时间:2023-11-29 00:38:36 25 4
gpt4 key购买 nike

我有一个带有以下代码的主视图 (view1)。当我点击某个部分中的单元格时,它将推送到另一个 View (view2),并且我希望该 view2 的标题与我点击的 view1 的部分标题相同。

查看1

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:headerView.frame];
imageView.image = [UIImage imageNamed:@"bg_blue.png"];
[headerView addSubview:imageView];

UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, kScreenWidth, 20)];
title.textColor = [UIColor whiteColor];
CategoryListData *data = self.dataArray[section];
title.text = data.categoryTitle;
[headerView addSubview:title];

return headerView;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
MainHeaderTableViewCell *tableCell = (MainHeaderTableViewCell *)collectionView.superview.superview;
CategoryListData *data = self.dataArray[tableCell.index];
CategoryDetailData *detailData = data.categoryList[indexPath.row];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
View2 *vc = [storyboard instantiateViewControllerWithIdentifier:@"View2"];
vc.detailData = detailData;
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}

查看2

- (void)initNavigationTitle {
[self setupNavigationTitle:self.detailData.title backButtonWithAnimated:YES]; // this line need to be replaced with section name from view1

}

我想在 view2 中做这样的事情

CategoryListData *data = self.dataArray[section];
title.text = data.categoryTitle;
[self setupNavigationTitle:title.text backButtonWithAnimated:YES];

但是我怎样才能将参数部分从 view1 传递到 view2?

最佳答案

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
MainHeaderTableViewCell *tableCell = (MainHeaderTableViewCell *)collectionView.superview.superview;
CategoryListData *data = self.dataArray[tableCell.index];
CategoryDetailData *detailData = data.categoryList[indexPath.row];

NSString *sectionTitle = [self.dataArray[tableCell.index] categoryTitle];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
View2 *vc = [storyboard instantiateViewControllerWithIdentifier:@"View2"];
vc.detailData = detailData;
vc.title = sectionTitle;
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}

关于ios - 将 TableView 部分标题传递给另一个 View 的导航栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40034395/

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