LoginSignup
4
4

More than 5 years have passed since last update.

UIbuttonをクラス拡張するとUIImagePickerControllerが使えなくなる。

Last updated at Posted at 2014-04-25

こんばんはnoppefoxwolfです。
タイトルが釣りっぽくなりましたが、UIbuttonのサブクラスみたいな感じでファイルを生成するとついつい陥りがちなので共有しておきます。
厳密にはクラス拡張をした上で
「initWithFrame:をオーバーライド」し、
「UIimagePickerControlerのsourcetypeをUIImagePickerControllerSourceTypeCameraに指定」すると
→アプリがクラッシュします。

クラス拡張なので(?)、@importしなくてもビルドの対象になっているだけで発生します。
何もいじってないのに急にカメラが使えなくなった!等の場合は疑ってみてください。

UIButton+Extention.h
#import <UIKit/UIKit.h>
@interface UIButton (Extention)
@end
UIbutton+Extention.m
#import "UIbutton+Extention.h"
@implementation UIButton (Layout)
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    return self;
}
@end

それ原因は実はそれじゃないよーとかあったらコメント頂ければと思います!
解消出来てよかったー!

追記:
クラス拡張内でオーバーライドするのが間違ってる!というコメントを見かけて、全くその通りなんですが、UIbuttonのサブクラスとしてファイル生成した後にやっぱ拡張にしようと@implementationだけ書き換えて使ったり横着するとうっかりinitが残ってたりするので気をつけます!ってやつです。

4
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4