2016-11-16 1 views
-2

カスタムUITextField:クリックしたTextField入力で、キーボードポップアップの後に背景を入力して再びフォアグラウンドに入ると、アプリクラッシュ!あなたは、TextField入力、背景や前景の変換をクリックしないとUITextFieldからenterBackground、アプリケーションクラッシュ

、それは正常であり、コードの一部:

@implementatio BKSearchViewController 
    - (void)setNavgationView { 
     BKSearchBar *searchBar = [[BKSearchBar alloc] initWithFrame:CGRectMake(20, 27, kScreenWidth - 90, 30)]; 
     searchBar.placeholder = @"输入昵称/拜托号"; 
     searchBar.delegate = self; 
     [searchBar setKeyboardType:UIKeyboardTypeDefault]; 
     [searchBar setReturnKeyType:UIReturnKeySearch]; 
     [searchBar setPlaceholderColor:kcallColor(@"a4a4a4")]; 
     [searchBar setPlaceholderFont:kFont(14)]; 
     [searchBar addTarget:self action:@selector(SearchTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; 
     [navgationView addSubview:searchBar]; 
    } 
    @end 

    //BKSearchBar The key code 
       @implementation BKSearchBar 
       - (id)initWithFrame:(CGRect)frame 
       { 
        self = [super initWithFrame:frame]; 
        if (self) { 
         // 设置背景 
         self.backgroundColor = kcallColor(@"7d1d57"); 
         self.returnKeyType = UIReturnKeySearch; 
         // 设置内容 -- 垂直居中 
         self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
         [self UI]; 
        } 
        return self; 
       } 
    - (void)UI{ 
     // 设置左边显示一个放大镜 
     UIImageView *leftView = [[UIImageView alloc] init]; 
     omit... 
     //右边的view 
     UIImageView *rightView = [[UIImageView alloc] init]; 
     omit... 
    } 
      - (CGRect)placeholderRectForBounds:(CGRect)bounds{ 
       CGRect rect = CGRectMake(self.leftView.right, (self.height - 24)/2, bounds.size.width, 14); 
       return rect; 
      } 
      - (void)clearText{ 
       self.text = nil; 
      } 
      - (void)setPlaceholderColor:(UIColor *)color{ 
       [self setValue:color forKeyPath:@"_placeholderLabel.textColor"]; 
      } 
      - (void)setPlaceholderFont:(UIFont *)font{ 
       [self setValue:font forKeyPath:@"_placeholderLabel.font"]; 
      } 
+1

「バックグラウンドまたはフォアグラウンド変換」?カントを取得して元のコードを表示するコードの画像を表示しないでください。 – vaibhav

+4

問題のコードのスクリーンショットを投稿せず、直接コードを投稿してください! – Lion

+0

UISearchBarデリゲートを実装しましたか?もしそうなら、そのコードを投稿して、何がうまくいかないかを知ることができます。 – CodeChanger

答えて

0

は、すべての感謝の問題が解決されるため、実行時の

!!!
+ (void)swizzleInstanceMethod:(Class)class originSelector:(SEL)originSelector otherSelector:(SEL)otherSelector 
{ 
    Method otherMehtod = class_getInstanceMethod(class, otherSelector); 
    Method originMehtod = class_getInstanceMethod(class, originSelector); 
    // 交换2个方法的实现 
    method_exchangeImplementations(otherMehtod, originMehtod); 
} 
関連する問題