iphone开发常见问题小集2 HA


1.莫名碰到[[[Class alloc] init] autorelease] 调用时执行 -(id)initWithFrame:(CGRect)frame 

 原因:没有 重载init方法,就默认执行 重载的frame方法 

2.UISerachBar 去除背景框

for (UIView *subview in searchBar.subviews) {
   
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
       
[subview removeFromSuperview];
       
break;
   
}

} 

3.响应键盘search事件{UITextFiled等同理}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{

} 

4.NSSelectorFromString使用

SEL blackSel = NSSelectorFromString(@"blackColor");

if ([UIColor respondsToSelector: blackSel])

self.view.backgroundColor  = [UIColor performSelector:blackSel]; 

5.图片边拉伸

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

 6.能正确获取当前设备方向的方法{在ViewController里}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

原文地址:https://www.cnblogs.com/halou/p/1992257.html