2
2

More than 5 years have passed since last update.

今日ハマったアレコレ Objective-C編

Posted at

KVOの受信できなくてハマった

自作クラスのプロパティ(NSArray)を登録したのに呼ばれない

//[self.tweets insertObject:statuses AtIndex:0];
//↑コレじゃ更新したことにならないみたいで
//↓これならOKだった
[self setValue:@[statuses] forKey:@"tweets"];

KVOでデータ更新したのを受信してLabelとか書き換えたのに画面更新しなくてハマった

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
//    [self reLoad:nil];←コレで更新しようと思っても再描画されない

// ↓別スレッドで更新メソッド呼んだら瞬時に終わった
    [NSThread detachNewThreadSelector:@selector(reLoad:)
                             toTarget:self
                           withObject:nil];

}

ACAccountStore使いたいのに認証確認画面を呼んでくれなくてハマった

requestAccessToAccountsWithTypeを呼ぶ

//[self.accountStore accountsWithAccountType:_twitterAcType];
//↑これがnilになるのに認証確認してくれない
//↓ requestAccessToAccountsWithTypeを呼んだら認証してない時に確認画面を表示してくれる
        [self.accountStore
         requestAccessToAccountsWithType:_twitterAcType
         options:NULL
         completion:^(BOOL granted, NSError *error) {
             if (granted) {
                 NSLog(@"outhentication:OK");
             }else{
                 NSLog(@"%@", [error localizedDescription]);
             }
         }];

UiViewがtouchesBeganとかtouchesEndedを取得できなくてハマった

結論から言うと、UIScrollViewはタッチイベントを取得できない仕様らしいです。

以下で解決
Objective-C - UIScrollViewに追加したUIImageViewのタッチイベントを取得する - Qiita [キータ]

2
2
0

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
2
2