2011-09-15 34 views
0

包含此警告的應用程序是否會通過App Store審閱?Objective-C UISearchBar可能不會響應setContentInset

隨着代碼,它實際上呈現在iPhone模擬器,但我應該如何刪除Xcode中的上述警告?

編輯2011年9月20:

我會後,有一天移除此警告的代碼。

EDIT 9 2011年10月:

這裏是我的解決方案,因爲我無法找到任何其他更好,更容易的解決方案:

UIView *extrablue = [[UIView alloc] initWithFrame:CGRectMake(250,0,80,40)]; 
    extrablue.backgroundColor = RGBCOLOR (95,95,95); 
    [self.view addSubview:extrablue]; 
    mySearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 250, 40)]; 
    //[mySearchBar setContentInset: UIEdgeInsetsMake(5,0,5,75)]; 
    mySearchBar.placeholder = @"Search a term here ... "; 
    mySearchBar.backgroundColor = RGBCOLOR (95,95,95); 
    mySearchBar.delegate = self; 
    //[mySearchBar sizeToFit]; 
    mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo; 
    [mySearchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone]; 
    [self.view addSubview: mySearchBar]; 

回答

2

UISearchBar不包含財產contentInset - 這是一個屬性UIScrollView。如果您的代碼要求UISearchBar更改其contentInset,那麼這是一個編碼錯誤,應該刪除。

如果您需要更多的幫助消除這一點,那麼一些額外的代碼將是有用的。

+0

我明白了。感謝您指出了這一點。 – wagashi

1

我發現的UISearchBar響應setContentInset:方法(在iOS 5.0.1測試)。

該結果在涉及NSInvocation的一個sofisticated的方法:使用的CGRect

if([aSearchBar respondsToSelector:@selector(setContentInset:)]) { 
     SEL aSelector = NSSelectorFromString(@"setContentInset:"); 
     NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[aSearchBar methodSignatureForSelector:aSelector]]; 
     [inv setSelector:aSelector]; 
     [inv setTarget:aSearchBar]; 
     UIEdgeInsets anInsets = UIEdgeInsetsMake(5, 0, 5, 35); 
     [inv setArgument:&anInsets atIndex:2]; //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation 
     [inv invoke]; 
    } 

上面的代碼大小調整的UISearchBar(有效的UITextField)的contentInset在anInsets參數指示。

父級if語句(respondsToSelector :)在新版本的iOS中保存此行爲的更改。

相關問題