【问题标题】:Using or Access class variable from UIActionSheetDelegate Methods使用或访问 UIActionSheetDelegate 方法中的类变量
【发布时间】:2011-05-27 12:09:13
【问题描述】:

在我的应用程序的一个视图中,它是 UIView 类的子类,我在工具栏(self.navigationController.toolBar)上有一个按钮。按下后,UIActionSheet 会弹出“删除”和“取消”。

myView.h

NSString *classVariable;
....
@property (nonatomic, retain) NSString *classVariable;

myView.m

@synthesize classVariable,...;
-(void) viewDidLoad {
     ...
     classVariable = [[NSString alloc] initWithString:@"blah"];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
     if (buttonIndex == 0) {
     ...
     NSLog(classVariable);//BUG HERE!! just cannot printout and app gets sudden death.
     }
}
-(void)dealloc{
     ...
     [classVariable release];
}

我不知道为什么我无法从 UIActionSheetDelegate 方法访问变量。我已经声明了变量并给出了值。

谢谢

【问题讨论】:

    标签: iphone objective-c delegates uiactionsheet


    【解决方案1】:

    你试过了吗:

    -(void) viewDidLoad {
         ...
         classVariable = [[NSString alloc] initWithString:@"blah"];
    }
    

    【讨论】:

    • 好点。不,我没有。但是可以从其他常规方法访问 String 变量。换句话说,我可以从除 UIActionSheet Delegate 方法之外的其他方法中获取 NSLog。那是我的问题。
    • 那我就糊涂了。在我自己的应用程序中,我用这种方法做了很多事情,这没关系。
    • IB 参考网点搞砸了。让我稍后删除这个帖子。
    • 原来它不是来自 IB 参考出口混乱。
    • 尽管我无法弄清楚我错过了什么,但您的建议是我经常犯的一个大错误。所以+1。非常感谢
    猜你喜欢
    • 2012-06-01
    • 2013-09-08
    • 2023-04-01
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    • 2017-08-22
    相关资源
    最近更新 更多