开发者

UIButtonType issue

I have created a UIButton by passing an integer value as this.

开发者_Python百科
 UIButton* custom_newBackButton = [UIButton buttonWithType:101];
 [custom_newBackButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
 [custom_newBackButton setTitle:@"Back" forState:UIControlStateNormal];

 UIBarButtonItem* newBackButton = [[UIBarButtonItem alloc] initWithCustomView:custom_newBackButton];
 [[self navigationItem] setLeftBarButtonItem: newBackButton];

In some of the classes this works but some of the classes it fails with "Invalid conversion from int to UIButtonType". Is this a recommended way to handle this. I have simply use this 101 to get the back button look and feel.

Regards,

Dilshan


The following button types are officially documented in the Apple documentation material:

typedef enum {
   UIButtonTypeCustom = 0,
   UIButtonTypeRoundedRect,
   UIButtonTypeDetailDisclosure,
   UIButtonTypeInfoLight,
   UIButtonTypeInfoDark,
   UIButtonTypeContactAdd,
} UIButtonType;

Enjoy! Please avoid using direct values. Values of constants might change and break your app.


Explicitly casting it to UIButtonType should work fine, though the constant is undocumented and would be rejected when submitting to App Store if the reviewer would aware of that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜