0

都市名を入力する必要がある場合は、UITextField があります。その都市名は URL にリンクされています: mywebsite/oslo など

しかし、ニューヨークに入ると、それは正しい URL ではありません。mywebsite/new york これである必要がありますhttp://www.website.com/New-York スペースを次のように置き換える UITextField を作成するにはどうすればよいですか: --> -

ご協力いただきありがとうございます!

- (void)configureControls {


[self.activityIndicator stopAnimating];

[UIView animateWithDuration:1.5 animations:^{

    if (self.weatherModel.lastLoadFailed) {
        self.locationTextField.enabled = YES;
        self.saveButton.hidden = NO;
        self.activityIndicator.hidden = YES;
        return;
    }

    self.settingsModel.location = self.locationTextField.text;


    PWForecastModel *forecast = self.weatherModel.sevenDayForecast[0];
    NSString *backgroundName = [PWHelper backgroundFileNameForConditionCode:forecast.conditions.conditionCode asDaytime:[[NSDate date] isDayTime]];
    if (![[NSDate date] isDayTime]) {
        [self styleControlsForDarkBackground];
    }
    self.backgroundImageView.image = [UIImage imageNamed:backgroundName];
    self.locationLabel.text = [NSString stringWithFormat:@"%@",self.weatherModel.cityName];
}];

}

4

3 に答える 3

0

デリゲート メソッドを呼び出す必要がありますtextFieldShouldEndEditing。そこにあなたはこれを使うだけstringByReplacingOccurrencesOfStringです。または、任意のイベントでこれを使用します。それで全部です 。お役に立てれば 。

参照:

   -(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
       //    NSString *str=  [textField.text stringByReplacingOccurrencesOfString:@" " withString:@"-"];
        //    NSLog(@"Testing: %@",str);
 textField.text = [NSString stringWithFormat:@"www.myweb.com/%@",[textField.text stringByReplacingOccurrencesOfString:@" " withString:@"-"]];
            return YES;
        }

私は思う、あなたはこれが必要です:

[self.weatherModel.cityName stringByReplacingOccurrencesOfString:@" " withString:@"-"];
于 2013-10-21T11:00:02.630 に答える
0

これを使って

 [searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
于 2013-10-21T10:44:07.050 に答える
-1

これを試して

NSString *string = @"Hi I am Indra          ";
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
                                  [NSCharacterSet whitespaceCharacterSet]];

文字列からスペースを置換する場合

NSString *str = @"This is a string";

str = [str stringByReplacingOccurrencesOfString:@" "
                                     withString:@""];
于 2013-10-21T10:43:25.710 に答える