V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Brutal
V2EX  ›  iDev

在 ActionSheet 中如何调用 segue 并且为 destinationViewController 赋值?

  •  
  •   Brutal · 2012-12-06 16:36:13 +08:00 · 5158 次点击
    这是一个创建于 4152 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用户点击某一个元素后调用 actionSheet:clickedButtonAtIndex: 这个方法。
    然后在这个方法中我需要跳转到下一个 view ,同时那个 view 需要一些赋值,比如

    TestViewController *vc = [[TestViewController alloc] init];
    vc.needValue = buttonIndex;

    然后再实现 segue 跳转到 vc。

    我试过用 performSegueWithIdentifier:sender: 它调用的是 prepareForSegue:sender: ,所以无法在这个方法中完成 actionSheet:clickedButtonAtIndex: 中的赋值?

    求解。。
    4 条回复    1970-01-01 08:00:00 +08:00
    eyeplum
        1
    eyeplum  
       2012-12-07 10:40:44 +08:00
    TestViewController *vc = [[TestViewController alloc] init];
    vc.needValue = buttonIndex;

    这里赋值不是这么赋的。你要找到 Segue 的实例 vc,而不是自己 init 一个。

    // Get reference to the destination view controller
    TestViewController *vc = [segue destinationViewController];

    // Pass any objects to the view controller here, like...
    vc.needValue = buttonIndex;

    看这里:http://stackoverflow.com/questions/7864371/ios5-how-to-pass-prepareforsegue-an-object
    eyeplum
        2
    eyeplum  
       2012-12-07 10:58:10 +08:00   ❤️ 1
    补充:如果你想要 actionSheet:clickedButtonAtIndex: 方法里的 buttonIndex 参数,我个人的做法是新建一个 property,比如 self.buttonIndexTapped 然后:
    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // ... 其他代码

    self.buttonIndexTapped = buttonIndex;

    // ... 其他代码
    }
    Brutal
        3
    Brutal  
    OP
       2012-12-07 11:38:52 +08:00
    @eyeplum 我最后也是这么做的,thx!
    zhigang1992
        4
    zhigang1992  
       2012-12-07 17:29:12 +08:00   ❤️ 1
    [self performSegueWithIdentifier:@"aIdentifier" sender:theActionSheet];

    然后,

    prepareForSegue:sender里面就可以取道actionSheet的值了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1008 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:31 · PVG 03:31 · LAX 12:31 · JFK 15:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.