开发者

Cannot call titleForRow method UIPickerView

开发者 https://www.devze.com 2023-04-03 08:10 出处:网络
in my viewcontroller class i have a property UIViewPicker myPicker. in didSelectRow method (also implemented by the UIPicker delegate. I try the following

in my viewcontroller class i have a property UIViewPicker myPicker. in didSelectRow method (also implemented by the UIPicker delegate. I try the following

NSString* temp = [self.myPicker titleForRow:1 inComponent:0].

However it says that the method is not found and says that return type defaults to "id".

What a开发者_开发技巧m i doing wrong????`


"it says that the method is not found" because this a delegate method for UIPickerViewDelegate. Check the Apple Documentation. Delegate methods are implemented, NOT called! Delegates are like listeners and their methods need to be implemented by the class that implements the delegates. The methods are called automatically and the order in which they are called is predefined. You only have to know the conditions under which they are called.

You can always create your own methods as long as they are different from the delegate methods.


This is a delegate method which you can use to set particular titles for rows. I don't believe you can call it via an instance like this. You'll need to implement this method separately in your current controller (which should implement the UIPickerViewDelegate) and then work from there.

e.g.

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

if (row==1)
    return @"Title 1";

if (row==2)
    return @"Title 2";

return @"Default Title";

}


try the following statement

NSString* temp = [self pickerView:self.myPicker titleForRow:1 forComponent:0];

I think,it will solve your problem.

Thanks

Satya


You can try like this

NSString* temp = [pickerView titleForRow:1 inComponent:0];

inside the mentioned method.

0

精彩评论

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