首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在参数传递中无法将“UIBarButtonItemStyle”转换为“UIBarButtonSystemItem”

在参数传递中无法将“UIBarButtonItemStyle”转换为“UIBarButtonSystemItem”
EN

Stack Overflow用户
提问于 2011-05-03 15:04:41
回答 2查看 2.6K关注 0票数 2

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

代码语言:javascript
复制
    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”

有没有解决这个问题的建议

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-03 15:09:48

代码语言:javascript
复制
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

代码语言:javascript
复制
typedef enum {
    UIBarButtonItemStylePlain,    // shows glow when pressed
    UIBarButtonItemStyleBordered,
    UIBarButtonItemStyleDone,
} UIBarButtonItemStyle;

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

票数 3
EN

Stack Overflow用户

发布于 2011-05-03 15:10:55

UIBarButtonItemStylePlain不是按钮的系统项样式。将其更改为以下任一项:

代码语言:javascript
复制
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)];

应该能让它工作起来。

我希望它能帮上忙

干杯

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5866200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档