我是iOS开发的新手,所以请原谅我提出愚蠢的问题或执行愚蠢的操作。
所以现在,这就是问题所在。我正在开发一个应用程序,最初有一个选项卡栏控制器,称为[Initial Tab View]。选项卡之一是显示所有项目的表格视图,我们称其为[Item View]。用户点击该单元格后,它将推到另一个视图并显示详细信息,即“详细信息视图”。另一个选项卡也是一个表格视图,但带有静态单元格[Static View],我用它来选择一个项目并返回。
为了获得更清晰的画面:如果我从初始选项卡视图访问[项目视图],只需遵循[初始选项卡视图]-> [项目视图]-> [详细视图]。但是,如果我先访问[静态视图],然后转到[项目视图],则过程将类似于[初始选项卡视图]-> [静态视图]-> [项目视图]-> [静态视图]。
我不知道如何在[项目视图]中实现第二个(使用[静态视图]),任何人都可以帮忙吗?还是有另一种更好的方法?非常感谢。
// Code from [Item View]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"CustomShopCell";
ShopCustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[ShopCustomTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:identifier];
}
if (searchResult != nil) {
//cell.textLabel.text = [searchResult objectAtIndex:indexPath.row];
Shop *shop = searchResult[indexPath.row];
if ([shop.shopNameChi length] == 0) {
cell.lblName.text = shop.shopName;
} else {
cell.lblName.text = [NSString stringWithFormat:@"%@ | %@", shop.shopName, shop.shopNameChi];
}
cell.lblLocation.text = shop.unit;
cell.imgImage.contentMode = UIViewContentModeScaleAspectFit;
cell.imgImage.image = [UIImage imageWithData:shop.imageData];
} else {
//cell.textLabel.text = [list objectAtIndex:indexPath.row];
Shop *shop = shopList[indexPath.row];
if ([shop.shopNameChi length] == 0) {
cell.lblName.text = shop.shopName;
} else {
cell.lblName.text = [NSString stringWithFormat:@"%@ | %@", shop.shopName, shop.shopNameChi];
}
cell.lblLocation.text = shop.unit;
cell.imgImage.contentMode = UIViewContentModeScaleAspectFit;
cell.imgImage.image = [UIImage imageWithData:shop.imageData];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(![self isKindOfClass:[NavigationMainTableViewController class]]){
[self performSegueWithIdentifier:@"showShopDetail" sender:self];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
您可以做的(如果我确定我了解您在做什么)是创建两个带有不同标识符的segue链接(使用清晰的名称,我喜欢这种格式“ fromHereToThere”)。然后在didselect中,您可以使用if语句调用segue,如下所示:
if (your condition){
[self performSegueWithIdentifier:@"fromHomeToStatic" sender:self];
}else{
[self performSegueWithIdentifier:@"fromHomeToDetail" sender:self];
}
然后,在您的prepareForSegue
方法(每个控制器类中默认为注释的方法)中,您可以选择要传递的数据
if ([segue.identifier isEqualToString:@"fromHomeToDetail"])
{
//Manage your usual stuff here for the detail identifier
//Ask me again if you need extra help with that
}
if ([segue.identifier isEqualToString:@"fromHomeToStatic"]){
//Manage here for the static identifier
}
但是我不是很确定你的意思是什么意思,所以我可能完全不关心主题:D
编辑:好的,显然,您想知道加载第三个控制器时来自何处。所以这是一种方法。
在目标控制器中,将其添加到.h中
@property (nonatomic) BOOL fromStatic;
(或您真正想要的任何东西)
然后在原始控制器中的prepareForSegue
,如果您来自静态,则将BOOL
下一个控制器的设置为YES
,如果不是,则将其设置为NO
,如下所示
DetailViewController *dvc = segue.destionationViewController;
dvc.fromStatic = YES; //if you're writing this from the static controller
在目标控制器的viewDidLoad中,只需检查它是否为YES或NO,然后做出相应的反应即可。
我是对的还是对您的问题感到困惑?我仍然不太确定你在问什么哈哈:D
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句