2012-10-06 43 views

回答

0

可以使用UIAlertView中做到這一點:

UIAlertView* alert = [[UIAlertView alloc] init]; 
alert.message = @"Enter new string"; 
alert.alertViewStyle = UIAlertViewStylePlainTextInput; 
UITextField* textField = [alert textFieldAtIndex:0]; 
textField.placeholder = @"text"; 

[alert addButtonWithTitle:@"Cancel"]; 
[alert addButtonWithTitle:@"OK"]; 
alert.cancelButtonIndex = 0; 
alert.delegate = self; 
[alert show]; 

處理 '確定' 按鈕按下:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (alertView.cancelButtonIndex != buttonIndex) { 
     NSString* text = [alertView textFieldAtIndex:0].text; 
     [self.myView setString:text]; 


    } 
} 

的方法自定義視圖應該設置它的NSString伊娃和呼叫[self setNeedsDisplay]setString: - 如果您知道繪製字符串的框架 - 請致電[self setNeedsDisplayInRect:stringFrame]

+0

謝謝你的幫助。它是有益的。 – mkaracan