Fab*_* B. 43 iphone storyboard uitableview ios ios5
有没有人知道如何有条件地"停止"segue过渡:
我的表格视图单元格表示可以在深入"详细"视图中查看的产品......或者不能!(这取决于几件事)
现在我的应用程序认为所有产品都"解锁":
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
ListaProdottiController *prodottiViewController = [segue destinationViewController];
prodottiViewController.blocco = [self.fetchedResultsController objectAtIndexPath:selectedRowIndex];
}
Run Code Online (Sandbox Code Playgroud)
此时如何取消行选择=>向下钻取?
Jos*_*des 79
如果您的目标是iOS 6或更高版本,那么我对最干净的方法的了解如下:
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if([identifier isEqualToString:@"show"])
{
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
Blocco *blocco = [self.fetchedResultsController objectAtIndexPath:selectedRowIndex];
return [blocco meetRequiredConditions];
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
哪里有方法
-(BOOL) meetsRequiredConditions;
Run Code Online (Sandbox Code Playgroud)
如果允许向下钻取的"几件事"有效,则在Blocco类上定义返回YES.
igb*_*pie 32
我不知道这是否是正确的方法,但我发现了一种解决方法.
从故事板中我将视图控制器中的状态栏关联(控制+单击)一个segue.给segue一个ID(例如:switchSegue).
现在,从您代码中的操作(在我的代码中我使用一个按钮),我调用:
[self performSegueWithIdentifier:@"switchSegue" sender:sender];
Run Code Online (Sandbox Code Playgroud)
这样你可以控制你的segue是否被执行.尝试从这里和这里帮助我的教程
希望这可以帮助.
zir*_*isp 18
我正在使用一种更简单,更整洁的方法.
故事板
表视图
这种方式看起来更容易实现,也不会改变segues的工作方式.
Som*_*Man 14
我可能在这里错了,但在努力解决这个问题之后,我只是禁用了单元格上的用户交互,我不希望触发seque(在cellForRowAtIndexPath :)中.似乎工作得很好,而且它只有一行代码!
cell.userInteractionEnabled = NO;
Run Code Online (Sandbox Code Playgroud)
小智 11
最简单的解决方案是在故事板中创建手动segue并使用如下所示.
[self performSegueWithIdentifier:@"loginSuccessSegue" sender:self];
Run Code Online (Sandbox Code Playgroud)
要么
@Fabio:我试图获得相同用例的解决方案,我几乎找到了解决方案.
用例1.有条件地停止segue转换2.有条件地更改目标viewController
解:
使用"自定义"segue.按照以下步骤创建自定义segue 1.创建UIStoryboardSegue"MyCustomSegue.h"的子类
@interface MyCustomSegue : UIStoryboardSegue
@end
Run Code Online (Sandbox Code Playgroud)
"MyCustomSegue.m"
覆盖initWithIdentifier以实现用例1和2如果返回nil,则将取消segue /不执行任何操作您实例化ViewController并将其设置为目标.您可以将目标设置为旧的xib文件..该代码已被注释,但我确保它可以正常工作.
@implementation MyCustomSegue
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination{
UIStoryboard *storyBoard= [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:@"testIdentifier"];
// MyViewController* viewController= [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];
return [super initWithIdentifier:identifier source:source destination:viewController];
}
Run Code Online (Sandbox Code Playgroud)
你也可以在这里实现用例1 ..
- (void)perform {
// if either source or destination is nil, stop
if (nil == self.sourceViewController || nil == self.destinationViewController) return;
// return; //No Action. Segue will be cancelled
UINavigationController *ctrl = [self.sourceViewController navigationController];
[ctrl
pushViewController:self.destinationViewController
animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.Plz写道,如果你不清楚.
归档时间: |
|
查看次数: |
31477 次 |
最近记录: |