在参数传递中不能将'UIBarButtonItemStyle'转换为'UIBarButtonSystemItem'

时间:2011-05-03 07:04:41

标签: iphone ipad

我正在尝试使用以下代码添加子视图包含uipickerview和Done按钮

    pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0,744, 768, 216)];
    mytab = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 700, 768, 44)];

    pickerView.alpha=0.0;
    mytab.alpha=0.0;


    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;

    [self.view addSubview:pickerView];
    [self.view bringSubviewToFront:pickerView]; 


    mytab.tintColor=[UIColor blackColor];

    UIBarButtonItem * bt1=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(_cancel)];
    UIBarButtonItem * flx=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

    NSArray *arr=[[NSArray alloc] initWithObjects:flx,bt1,nil];
    [mytab setItems:arr];
    [self.view addSubview:mytab];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    pickerView.alpha=1.0;
    mytab.alpha=1.0;
    [UIView commitAnimations];


    [pickerView release];
    [mytab release];
    [bt1 release];
    [flx release];
    [arr release];

它引发以下错误

无法在参数传递中将'UIBarButtonItemStyle'转换为'UIBarButtonSystemItem'

解决这个问题的一个建议

2 个答案:

答案 0 :(得分:3)

typedef enum {
    UIBarButtonSystemItemDone,
    UIBarButtonSystemItemCancel,
    UIBarButtonSystemItemEdit,  
    UIBarButtonSystemItemSave,  
    UIBarButtonSystemItemAdd,
    UIBarButtonSystemItemFlexibleSpace,
    UIBarButtonSystemItemFixedSpace,
    UIBarButtonSystemItemCompose,
    UIBarButtonSystemItemReply,
    UIBarButtonSystemItemAction,
    UIBarButtonSystemItemOrganize,
    UIBarButtonSystemItemBookmarks,
    UIBarButtonSystemItemSearch,
    UIBarButtonSystemItemRefresh,
    UIBarButtonSystemItemStop,
    UIBarButtonSystemItemCamera,
    UIBarButtonSystemItemTrash,
    UIBarButtonSystemItemPlay,
    UIBarButtonSystemItemPause,
    UIBarButtonSystemItemRewind,
    UIBarButtonSystemItemFastForward,
#if __IPHONE_3_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    UIBarButtonSystemItemUndo,
    UIBarButtonSystemItemRedo,
#endif
#if __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    UIBarButtonSystemItemPageCurl,
#endif
} UIBarButtonSystemItem;

UIBarButtonItemStylePlain不适用于UIBarButtonSystemItem。它适用于UIBarButtonItemStyle

typedef enum {
    UIBarButtonItemStylePlain,    // shows glow when pressed
    UIBarButtonItemStyleBordered,
    UIBarButtonItemStyleDone,
} UIBarButtonItemStyle;

您可以尝试使用- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action;按钮

答案 1 :(得分:0)

UIBarButtonItemStylePlain不是Button的系统项样式。更改以下任何一项:

typedef enum {
UIBarButtonSystemItemDone,
UIBarButtonSystemItemCancel,
UIBarButtonSystemItemEdit,
UIBarButtonSystemItemSave,
UIBarButtonSystemItemAdd,
UIBarButtonSystemItemFlexibleSpace,
UIBarButtonSystemItemFixedSpace,
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply,
UIBarButtonSystemItemAction,
UIBarButtonSystemItemOrganize,
UIBarButtonSystemItemBookmarks,
UIBarButtonSystemItemSearch,
UIBarButtonSystemItemRefresh,
UIBarButtonSystemItemStop,
UIBarButtonSystemItemCamera,
UIBarButtonSystemItemTrash,
UIBarButtonSystemItemPlay,
UIBarButtonSystemItemPause,
UIBarButtonSystemItemRewind,
UIBarButtonSystemItemFastForward,
UIBarButtonSystemItemUndo,        // iOS 3.0 and later
UIBarButtonSystemItemRedo,        // iOS 3.0 and later
UIBarButtonSystemItemPageCurl,    // iOS 4.0 and later
} UIBarButtonSystemItem;

行:UIBarButtonItem * bt1=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(_cancel)];

应该让它发挥作用。

我希望它有所帮助

干杯