2010-05-25 64 views
0

對於那些你們誰圖形工作,這裏是視圖層次結構的示意圖:UITextField停止搖動事件?

Root View -> UINavigationController -> UITableView -> Edit View -> Problem UITextfield

基本上,當設備震動- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event;被稱爲我的根視圖。

當用戶點擊「編輯」圖標(筆,在屏幕的底部 - 不是傳統的UINavigationBar編輯按鈕),主視圖添加一個子視圖到自己,並使用動畫在屏幕上使用自定義動畫。

這個子視圖包含一個UINavigationController,它包含一個UITableView。 UITableView在單元被點擊時將子視圖加載到自身中。第二個子視圖是罪魁禍首。由於某種原因,第二個子視圖中的UITextField會導致問題。

當用戶點擊視圖時,除非UITextField處於活動狀態(處於編輯模式?),否則主視圖不會響應抖動。

附加信息:

我的議案事件處理程序:

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { 
NSLog(@"%@", [event description]); 
SystemSoundID SoundID; 
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"shake" ofType:@"aif"]; 
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &SoundID); 
AudioServicesPlayAlertSound(SoundID); 
[self genRandom:TRUE]; 
} 

genRandom:方法:

/* Generate random label and apply it */ 
-(void)genRandom:(BOOL)deviceWasShaken{ 
if(deviceWasShaken == TRUE){ 
    decisionText.text = [NSString stringWithFormat: (@"%@", [shakeReplies objectAtIndex:(arc4random() % [shakeReplies count])])]; 
}else{ 
    SystemSoundID SoundID; 
    NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"string" ofType:@"aif"]; 
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &SoundID); 
    AudioServicesPlayAlertSound(SoundID); 
    decisionText.text = [NSString stringWithFormat: (@"%@", [pokeReplies objectAtIndex:(arc4random() % [pokeReplies count])])]; 
} 
} 

shakeRepliespokeReplies都是NSArrays的字符串。一個用於屏幕的某個部分被戳穿,另一個用於設備被震動時。該應用程序將從NSArray中隨機選擇一個字符串並顯示在屏幕上。

一如既往,代碼示例表示讚賞。 我已經添加了我自己的來幫助解釋這個問題。

+0

如何在子視圖中的鍵盤? – 2010-05-25 04:22:32

+0

不再相關,請關閉。 – Moshe 2010-06-10 17:59:47

回答

1

鍵盤:尋找UIKeyboardAppearanceAlert

至於抖動檢測。一旦UITextField辭職第一響應者(不在焦點,鍵盤隱藏),你需要確保鏈中的另一個UIResponder成爲firstResponder。舉例來說,如果你有一個按鈕,發送-resignFirstResponder文本字段,你需要這樣做:

- (IBAction)pressButton { 
    [textField resignFirstResponder]; 
    [self becomeFirstResponder]; 
} 
+0

這完成了它的工作並首先發布。儘管答案不完整。 – Moshe 2010-06-03 18:58:10

1

嘗試使用[self.view endEditing:YES];

和鍵盤是玻璃的使用:

[textfield setKeyboardAppearance:UIKeyboardAppearanceAlert]; 

希望這會有所幫助。 謝謝, Madhup

+0

第一種方法是我嘗試的方法。沒有什麼在那裏做,沒有工作。 – Moshe 2010-06-03 18:57:08