UIResponder of UIKit framework
3304 단어 res
1. Code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"window:%@",[self.window nextResponder]);
NSLog(@"AppDelegate: %@",[self nextResponder]);
return YES;
}
//
// ViewController.m
// UIResponder
//
// Created by cyw on 15-5-16.
// Copyright (c) 2015 cyw. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UITextFieldDelegate>
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UITextField *textField=[[UITextField alloc]init];
textField.frame=CGRectMake(100, 100, 100, 40);
textField.borderStyle=UITextBorderStyleLine;
textField.backgroundColor=[UIColor redColor];
textField.delegate=self;
textField.tag=10001;
BOOL canBecomeFirstResponder=[textField canBecomeFirstResponder ];
BOOL canResignFirstResponder=[textField canResignFirstResponder];
NSLog(@"%d %d",canBecomeFirstResponder,canResignFirstResponder);
[textField becomeFirstResponder];
[self.view addSubview:textField];
UITextField *textField1=[[UITextField alloc]init];
textField1.frame=CGRectMake(100, 200, 100, 40);
textField1.borderStyle=UITextBorderStyleLine;
textField1.backgroundColor=[UIColor redColor];
textField1.delegate=self;
textField1.tag=10002;
[self.view addSubview:textField1];
UIResponder *responder1= [textField nextResponder];
UIResponder *responder2=[self nextResponder];
UIResponder *responder3=[self.view nextResponder];
NSLog(@"textField:%@
ViewController:%@
self.view:%@",responder1,responder2,responder3);
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
BOOL isFirstResponder= [textField isFirstResponder];
NSLog(@"textField%d isFirstResponder %d:",textField.tag,isFirstResponder);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
2. Results
2015-05-17 00:30:02.427 UIResponder[1132:60b] window:<UIApplication: 0x8d71b80>
2015-05-17 00:30:02.437 UIResponder[1132:60b] AppDelegate: (null)
2015-05-17 00:30:02.446 UIResponder[1132:60b] 1 1
2015-05-17 00:30:02.449 UIResponder[1132:60b] textField:<UIView: 0x8e742d0; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0x8e739e0>>
ViewController:(null)
self.view:<ViewController: 0x8c9b8c0>
2015-05-17 00:30:02.463 UIResponder[1132:60b] textField10001 isFirstResponder 1:
3. From the above output results, I am a little puzzled, why ViewController returns NULL? I thought about it for a long time and couldn't think of any reason, please give pointers to experts
Fourth, in fact, UIResponder is not only these, you can refer to: http://southpeak.github.io/blog/2015/03/07/uiresponder/?utm_source=tuicool
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
success: function (res) {} 와success:res => {}위챗 프로그램은userinfo를 가져오는 과정에서this를 사용하여 몇 가지 문제에 부딪혔다 나login의success 리셋 함수는 여기의this는 다음과 같이 오류를 보고합니다. Cannot read propert...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.