經典錯誤
報錯>>>>>>-[UIView setSelected:]: unrecognized selector sent to instance 0x7ff3f35b1070
報錯原因>>>>>>錯誤將UIView當作按鈕來使用使用
報錯>>>>>>>>-[XMGPerson length]: unrecognized selector sent to instance 0x7ff3f35b1070
報錯原因>>>>>>>>錯誤將XMGPerson當做NSString來使用,比如
id obj = [[XMGPerson alloc] init];
NSString *string = obj;
string.length;
報錯>>>>>-[XMGPerson setObject:forKeyedSubscript:]: unrecognized selector sent to instance 0x7ff3f35b1070
報錯原因>>>>>>>錯誤將XMGPerson當做NSMutableDictionary來使用
規律: 方法名里面包含了Subscript的方法,一般都是集合的方法(比如字典\數組)
@implementation UIView
- (UIView *)viewWithTag:(NSInteger)tag
{
// 如果自己的tag符合要求, 就返回自己
if (self.tag == tag) return self;
// 遍歷子控件,查找tag符合要求的子控件
for (UIView *subview in self.subviews) {
// if (subview.tag == tag) return subview;
UIView *resultView = [subview viewWithTag:tag];
if (resultView) return resultView;
}
// 找不到符合要求的子控件
return nil;
}
@end
/**
* 可以在這個AppDelegate方法中監聽到狀態欄的點擊
*/
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if ([touches.anyObject locationInView:nil].y > 20) return;
NSLog(@"點擊了狀態欄")
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。