开发者

shows warning msg at the end of the UIPickerViewDelegate method

I have created a pickerview in my application and create two component of it for that in my .h file code is as follows

@interface tweetViewController : UIViewController<UIPickerViewDataSource ,UIPickerViewDelegate> {

    NSArray *activities;
    NSArray *feelings;

}
@property(nonatomic,retain) NSArray *activities;
@property(nonatomic,retain) NSArray *feelings;
@end

after that in my .m file i have implemented compulsory method for UIPickerViewDataSource and UIPickerViewDelegate but both compulory methods of UIPickerViewDatasource works fine and its code is

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
        return [activities count];
    }
    else
    {
        return [feelings count];
    }
} return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component==0) {
   return [activities count];
    }
    else
    {
        return [feelings count];
    }
}

but the method of UIPickerViewDelegate shows warning at the end of the method

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComp开发者_如何学编程onent:(NSInteger)component
{
    switch (component) {
        case 0:
            return [activities objectAtIndex:row];
            break;
        case 1:
            return [feelings objectAtIndex:row];
            break;
    }

}

tell me why does the warning occur????


The warning "control may reach end of non-void function.." means to say that the method is returning nothing as the method is having some return value.

    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
        NSString *strToReturn = @"";
        switch (component) {
            case 0:
                strToReturn = [activities objectAtIndex:row];
                break;
            case 1:
                strToReturn = [feelings objectAtIndex:row];
            break;
        }
        return strToReturn;
    }

Modify your code as above and the warning will be no more to irritate you.


//numberOfRowsInComponent must return NSInteger value

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component==0) {
        return [activities count];//then wont execute feelings count
    }//if loop failed then ur feeling count

    return [feelings count];
}

//here u can remove else loop with same meaning with your context 

for titleForRow method u have to return nsstring in atleast in default case

so specify defaust case for some some string

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜