我有一個主視圖(view1)與下面的代碼。當我點擊某個部分中的單元格時,它將推向另一個視圖(視圖2),並且我希望該視圖2的標題與我點擊的視圖1的部分標題相同。傳遞tableview節標題到另一個視圖的導航欄標題
廠景
- (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
}
我試圖做這樣的事情在視圖2
CategoryListData *data = self.dataArray[section];
title.text = data.categoryTitle;
[self setupNavigationTitle:title.text backButtonWithAnimated:YES];
但我怎樣才能將參數部分從view1傳遞給view2?
您可以顯示代碼如何推視圖2。 –
@ New16好吧我剛更新了問題 – SanitLee
那麼你有沒有在tableview單元格中使用集合視圖? – ashmi123