我已經爲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