Objective-C UISearchBar可能对setContentInset无效

Objective-C UISearchBar可能对setContentInset无效,objective-c,uisearchbar,compiler-warnings,Objective C,Uisearchbar,Compiler Warnings,包含此警告的应用是否通过应用商店审核 有了这些代码,它实际上会在iPhone模拟器中呈现出来,但是我应该如何在Xcode中删除上面提到的警告呢 2011年9月20日编辑: 有一天我会发布删除此警告的代码 2011年10月9日编辑: 这是我的解决方案,因为我找不到其他更好更简单的解决方案: UIView *extrablue = [[UIView alloc] initWithFrame:CGRectMake(250,0,80,40)]; extrablue.backgroundC

包含此警告的应用是否通过应用商店审核

有了这些代码,它实际上会在iPhone模拟器中呈现出来,但是我应该如何在Xcode中删除上面提到的警告呢

2011年9月20日编辑:

有一天我会发布删除此警告的代码

2011年10月9日编辑:

这是我的解决方案,因为我找不到其他更好更简单的解决方案:

    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];

UISearchBar
不包含属性
contentInset
-这是
UIScrollView
的属性。如果您的代码要求
UISearchBar
更改其
contentInset
,则这是一个编码错误,应将其删除


如果您需要进一步的帮助来删除此项,那么一些附加代码将非常有用。

UISearchBar
不包含属性
contentInset
-这是
UIScrollView
的属性。如果您的代码要求
UISearchBar
更改其
contentInset
,则这是一个编码错误,应将其删除


如果您需要进一步的帮助来删除此项,那么一些额外的代码将非常有用。

我发现UISearchBar响应setContentInset:方法(在iOS 5.0.1上测试)

这导致了一种涉及n干扰:

    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];
    }
上面的代码使用ANISETS参数中指示的CGRect调整UISearchBar(实际上是UITextField)的contentInset的大小


父if语句(respondsToSelector:)可以避免在新版本的iOS中更改此行为。

我发现UISearchBar响应setContentInset:方法(在iOS 5.0.1上测试)

这导致了一种涉及n干扰:

    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];
    }
上面的代码使用ANISETS参数中指示的CGRect调整UISearchBar(实际上是UITextField)的contentInset的大小

父if语句(respondsToSelector:)可以避免在新版本的iOS中更改此行为