键入Cast UIView警告

时间:2012-05-01 19:03:32

标签: iphone objective-c ios casting

我一直警告UIView可能不会响应selectedSegmentIndex。我尝试了类型转换,但我无法摆脱警告。我假设我做错了。

键入强制转换的正确方法是什么,以避免警告?

- (IBAction)segmentedControlIndexChanged:(id)sender
{    
    switch ([[[[self.view viewWithTag:100] viewWithTag:202] viewWithTag:203] selectedSegmentIndex]) {

        case 0:
            // code here
            break;
        case 1:
            // code here
            break;
        default:
            break;
    }
}

1 个答案:

答案 0 :(得分:2)

试试这个:

switch ([ (UISegmentedControl*)[[[self.view viewWithTag:100] viewWithTag:202] viewWithTag:203] selectedSegmentIndex]) {
...