2

处理应用程序并使用 resignFirstResponder 方法编辑文本。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return YES;
}// return NO to disallow editing.

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    CGPoint scrollPoint = CGPointMake(0, textField.frame.origin.y);
    [scrollView setContentOffset:scrollPoint animated:YES];
}// became first responder

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    return YES;
}// return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end

- (void)textFieldDidEndEditing:(UITextField *)textField {
    [scrollView setContentOffset:CGPointZero animated:YES];
}// may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called

- (BOOL)textFieldShouldClear:(UITextField *)textField {
    return NO;
}// called when clear button pressed. return NO to ignore (no notifications)


-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
    NSInteger nextTag = textField.tag + 1;
    // Try to find next responder
    UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
    if (nextResponder) {
        // Found next responder, so set it.
        [nextResponder becomeFirstResponder];
    } else {
        // Not found, so remove keyboard.
        [textField resignFirstResponder];
    }
    return NO; // We do not want UITextField to insert line-breaks.
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    if ([emailField isFirstResponder] && [touch view] != emailField) {
        [emailField resignFirstResponder];
    }
    else if ([passwordField isFirstResponder] && [touch view] != passwordField) {
        [passwordField resignFirstResponder];
    }
    [super touchesBegan:touches withEvent:event];
}

我已经研究了很长时间..但是应用程序随机崩溃。有时运行流畅,有时在我点击任何 UIEdittext 后立即崩溃。

请帮忙。我也尝试过:当用户点击其他地方时,如何从文本字段中退出第一响应者?

但它也会在随机情况下以关闭键盘方法崩溃。找不到那个..请帮忙。

设备日志

Oct  8 19:09:28 iPhone-5 wifid[15] <Notice>: WiFi:[402934168.667607]: 
Oct  8 19:09:28 iPhone-5 wifid[15] <Notice>: Too frequent(0.169014 secs) rssi event from driver, ignoring
Oct  8 19:09:28 iPhone-5 wifid[15] <Notice>: 
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.114689]: WiFiLocaleManagerCheckLocale: trying to determine locale...
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.115691]: WiFiManagerCoreLocationGetCachedLocation: getting cached location...
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.119252]: __WiFiLocaleManagerGetLocaleFromMcc: finding iso country code for mcc 410 ....
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.119628]: Starting Low Accuracy Location Monitoring, locationMonitoringTimeout=60.000000
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.120057]: WiFiManagerCoreLocationStartLocationUpdates: starting location updates...
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.120356]: Location Monitoring successfully started with accuracy=3000.000000meters
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.120673]: __WiFiLocationServiceManagerEventCallback, got cb dict <dictionary> {
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>:   eventType : 0
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>:   location : <+33.53914677,+73.10165631> +/- 1414.00m (speed -1.00 mps / course -1.00) @ 10/8/13, 7:09:36 PM Pakistan Standard Time
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: }
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.124702]: __WiFiLocationServiceManagerProcessLocationAvailableEvent: isValidHighAccuracyLocation 0,  isValidLowAccuracyLocation 1
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.125013]: __WiFiLocationServiceManagerProcessLocationAvailableEvent: give low accuracy callback
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.125276]: __WiFiLocaleManagerGetLocaleFromLocation: <+33.53914677,+73.10165631> +/- 1414.00m (speed -1.00 mps / course -1.00) @ 10/8/13, 7:09:36 PM Pakistan Standard Time
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.127336]: locale from bounding box 
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.127564]: new locale:  , locale: 
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.127795]: Stopping Low Accuracy Location Monitoring
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.128050]: Location Monitoring stopped
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.128296]: WiFiManagerCoreLocationStopLocationUpdates: stopping location updates...
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.128696]: Stopping Low Accuracy Location Monitoring
Oct  8 19:09:36 iPhone-5 wifid[15] <Notice>: WiFi:[402934176.128949]: CLMonitoring is already stopped
Oct  8 19:09:37 iPhone-5 wifid[15] <Notice>: WiFi:[402934177.474861]: 
Oct  8 19:09:37 iPhone-5 wifid[15] <Notice>: Too frequent(3.971344 secs) rssi event from driver
Oct  8 19:09:37 iPhone-5 wifid[15] <Notice>: 
Oct  8 19:09:38 iPhone-5 wifid[15] <Notice>: WiFi:[402934178.504655]: 
Oct  8 19:09:38 iPhone-5 wifid[15] <Notice>: Too frequent(1.029793 secs) rssi event from driver
Oct  8 19:09:38 iPhone-5 wifid[15] <Notice>: 
Oct  8 19:09:58 iPhone-5 wifid[15] <Notice>: WiFi:[402934198.509395]: 
Oct  8 19:09:58 iPhone-5 wifid[15] <Notice>: Too frequent(4.996233 secs) rssi event from driver
Oct  8 19:09:58 iPhone-5 kernel[0] <Debug>: AppleD1972PMUPowerSource: limiting USB input current to 490 mA (measured 496 mA)
Oct  8 19:09:58 iPhone-5 kernel[0] <Debug>: AppleD1972PMUPowerSource: limiting USB input current to 390 mA (measured 468 mA)
Oct  8 19:09:58 iPhone-5 kernel[0] <Debug>: 086669.986712 wlan.A[10295] AppleBCMWLANNetManager::updateLinkQualityMetrics(): Report LQM to User Land 100, fAverageRSSI -70
Oct  8 19:09:58 iPhone-5 wifid[15] <Notice>: 

在此处输入图像描述

4

0 回答 0