2013-05-06 3 views
0

Я использую этот кодКак удалить скобки в UIAlertView

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled" 
    message:[NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",selected_phone_numbe ,selectedOption] 
    delegate:self cancelButtonTitle:@"Ok" 
    otherButtonTitles:nil, nil]; 

I want remove the brackets in alert view

ответ

0

selected_phone_numbe и selectedOption выглядит либо массив, либо сама строка содержит (и).

Проверьте тип класса (интроспекция класса), если это массив, используйте массив [0].

Если строка, то вы можете заменить ( & ) пустой пустой.

0

Я думаю selected_phone_numbe & selectedOption приходит с этим кронштейном удалить его, а затем использовать его в оповещении

NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()"]; 
s = [s stringByTrimmingCharactersInSet:charsToTrim]; 
1

Перед тем как показывать предупреждение, вы можете поместить этот код, вы можете сразу же заменить все нежелательные символы.

NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"()"];// declare set of unwanted charecters here. 

selected_phone_numbe = [[selected_phone_numbe componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""]; 

selectedOption = [[selectedOption componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""]; 
1
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled" 
                 message:[NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",[[selected_phone_numbe stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""] ,[[selectedOption stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""]] 
                 delegate:self cancelButtonTitle:@"Ok" 
               otherButtonTitles:nil, nil]; 
    [alertView show]; 

Выход:

enter image description here

+0

хороший ответ venket, но u можете оптимизировать ур ответ – Ron

0

Пожалуйста, попробуйте использовать этот. Я надеюсь, что это может вам помочь.

NSString *msgStr = [NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",selected_phone_numbe ,selectedOption] 

    msgStr = [msgStr stringByReplacingOccurrencesOfString:@"(" withString:@""]; 
    msgStr = [msgStr stringByReplacingOccurrencesOfString:@")" withString:@""]; 

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled" 
    message:msgStr delegate:self cancelButtonTitle:@"Ok" 
    otherButtonTitles:nil, nil]; 
0

Попробуйте:

NSString * changeString = [NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",[[selected_phone_numbe stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""] ,[[selectedOption stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""]]; 
    UIAlertView *callAlert = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled" 
                 message:changeString 
                 delegate:self cancelButtonTitle:@"Ok" 
               otherButtonTitles:nil, nil]; 
    [callAlert show]; 

и проверить этот метод:

-(NSString *)replacingString:(NSString*)mainString removeString:(NSString *)rmString withReplace:(NSString*)rpString{ 
    mainString = [mainString stringByReplacingOccurrencesOfString:rmString withString:rpString]; 

    return mainString; 

} 

Вы получили ответ на свой вопрос;

Спасибо :)

Смежные вопросы