我已经为ToastView(类似于Android的面包)创建了一个iOS类,它在屏幕底部显示一个消息栏。我向ToastView添加了一个按钮,并解决了我原来的错误。用于触摸按钮的NSLog显示在控制台中,但是当点击按钮时我需要将BOOL值发送回HomeViewController,并且我不确定如何使用此按钮在两者之间进行通信。任何帮助?iOS中的Android“Toast”:将按钮添加到消息
在ToastView.h:
+ (void)showToastInParentView: (UIView *)parentView withText:(NSString *)text withDuaration:(float)duration;
+ (void)undoButtonClicked:(id)sender;
在ToastView.m:
//shows the "toast" message
+ (void)showToastInParentView: (UIView *)parentView withText:(NSString *)text withDuaration:(float)duration {
//code to show message
UIButton *undoButton = [[UIButton alloc] initWithFrame:CGRectMake(toast.frame.size.width - 60.0, toast.frame.size.height - 35.0, 40, 20)];
undoButton.backgroundColor = [UIColor lightGrayColor];
[undoButton addTarget:self action:@selector(undoButtonClicked:) forControlEvents:UIControlEventTouchDown];
}
+(void) undoButtonClicked:(id)sender {
NSLog(@"UNDO BUTTON TOUCHED");
}
和我在HomeViewController调用ToastView用下面的代码:
[ToastView showToastInParentView:self.view withText:@"TOAST MESSAGE!" withDuaration:5.0];
貌似undoButtonClicked被定义为一个对象的方法,但你可能会调用它直接在课堂上。你在任何地方使用* [ToastView undoButtonClicked:someParameter]; *? – rdurand 2014-10-09 15:50:36
如果是这样,让我知道如果将它改为* [self undoButtonClicked:someParameter]; *效果更好,所以我可以写一个完整的答案 – rdurand 2014-10-09 15:55:32
我不知道。我没有发送任何参数到undoButtonClicked :,我只需要知道按钮被触摸的时间。我需要在应用程序中调用此位置? – 2014-10-09 15:57:03