1) Trong phương pháp - (id) initWithAlertTitle: (NSString *) tiêu đề checkForPassword: (NSString *) mật khẩu
bạn nên thêm
self.alertViewStyle = UIAlertViewStylePlainTextInput;
mẫu:
(id)initWithAlertTitle:(NSString *)title
checkForPassword:(NSString *)password{
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
self.alertViewStyle = UIAlertViewStylePlainTextInput;
}
self = [super initWithTitle:title
message:@"" // password field will go here
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Enter", nil];
if (self) {
self.password = password;
self.hashTechnique = HashTechniqueNone; // use no hashing by default
secondMessage = @"Please Enter New Password";
thirdMessage = @"Please Re-Enter Password";
secondMessageNew = @"Please Enter Password";
}
NSLog(@" _password_ %@",_password);
NSLog(@"_old_password_ %@",[[NSUserDefaults standardUserDefaults] objectForKey:kPassword]);
return self;
}
trong phương thức hiển thị thêm tiếp theo
(void)show {
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
UITextField *passwordField = [self textFieldAtIndex:0];
passwordField.delegate = self;
self.passwordField = passwordField;
}
else
{
UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(14, 45, 256, 25)];
passwordField.secureTextEntry = YES;
passwordField.placeholder = @"";
passwordField.backgroundColor = [UIColor whiteColor];
// Pad out the left side of the view to properly inset the text
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 6, 19)];
passwordField.leftView = paddingView;
passwordField.leftViewMode = UITextFieldViewModeAlways;
// // Set delegate
self.passwordField.delegate = self;
// Set as property
self.passwordField = passwordField;
// Add to subview
[self addSubview:_passwordField];
}
// Show alert
[super show];
}
cũng thực hiện thay đổi trong phương pháp bấm
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
UITextField *passwordField = [self textFieldAtIndex:0];
self.passwordField = passwordField;
}
if (buttonIndex == alertView.firstOtherButtonIndex) {
if ([self enteredTextIsCorrect] || [self.title isEqualToString:secondMessage] || [self.title isEqualToString:secondMessageNew]) {
if (([self.title isEqualToString:secondMessage] || [self.title isEqualToString:secondMessageNew]) && (self.passwordField.text.length > 0)) {
self.password = self.passwordField.text;
self.title = thirdMessage;
self.passwordField.text = @"";
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
if ([self.passwordDelegate respondsToSelector:@selector(notifyParent::)]) {
[self.passwordDelegate notifyParent:thirdMessage:self.password];
}
}
}else
{
if ([self.title isEqualToString:thirdMessage]) {
[[NSUserDefaults standardUserDefaults] setObject:self.password forKey:kPassword];
[[NSUserDefaults standardUserDefaults] synchronize];
if (self.passwordDelegate) {
if ([self.passwordDelegate respondsToSelector:@selector(notifyParentWithState:)]) {
[self.passwordDelegate notifyParentWithState:YES];
}
}
}else{
if ([self.title isEqualToString:secondMessageNew]) {
self.title = secondMessageNew;
}
else{
self.title = secondMessage;
}
self.passwordField.text = @"";
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
if ([self.passwordDelegate respondsToSelector:@selector(notifyParent::)]) {
[self.passwordDelegate notifyParent:self.title:self.password];
}
}
}
}
}
// If incorrect then animate
else {
[self animateIncorrectPassword];
}
}
}
iOS7 vẫn là _beta_, bạn mong đợi điều gì? – holex
Vâng ... Tôi đoán nếu Apple sắp phát hành iOS7 vào giữa tháng 9, tôi hy vọng có thể làm việc với một cộng đồng các nhà phát triển tài năng, sáng sủa và có đầu óc để Ứng dụng của chúng tôi không thể sử dụng được cho hàng ngàn Apple hiện có người dùng. Có vẻ ngớ ngẩn đến nỗi Apple không mong đợi bất kỳ ai nói về cách chủ động trong việc giữ cho người dùng của họ hạnh phúc. Vậy chúng ta có giả vờ rằng iOS7 không tồn tại cho đến khi nó chính thức được phát hành không?NDA là quan trọng, nhưng điều này có vẻ ngớ ngẩn ... và thậm chí sillier rằng ai đó đang dành thời gian để đi qua các câu hỏi iOS7 và điểm ding từ người dân. Chỉ cần nói ... – iTrout
Apple cung cấp một diễn đàn để thảo luận về iOS7 trong đó API bị cấm vận có thể được thảo luận. Các thảo luận ở đây về phần mềm chưa được phát hành và có thể không hoạt động không hữu ích cho người khác - trừ khi được gắn thẻ đặc biệt với số phiên bản – marko