0

我试图用 UIImage 设置右键项目:

它推动了我以编程方式创建的 UINavbar(它是 IBOutlet 并在情节提要中使用)左按钮和右按钮。左按钮工作得很好,而不是右按钮似乎没有被初始化。

在标题中:

@property (weak, nonatomic) IBOutlet UINavigationBar *navBar;

我尝试的是:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", self.userDestFBID]];

NSData *imageData = [NSData dataWithContentsOfURL:url];

UIImage *destProfileImage = [UIImage imageWithData:imageData];

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithImage:_destProfileImage style:UIBarButtonItemStyleDone target:self action:@selector(goBack)];

_item = [[UINavigationItem alloc] initWithTitle:nil];

_item.hidesBackButton = YES;

_item.leftBarButtonItem = activityItem;

_item.rightBarButtonItem = rightButton;

[_navBar pushNavigationItem:_item animated:YES];

任何帮助将不胜感激 ..

4

1 回答 1

0
 UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
  [button setImage:[UIImage imageNamed:_destProfileImage] forState:UIControlStateNormal];
  [button addTarget:self action:@selector(action:)forControlEvents:UIControlEventTouchUpInside];
  [button setFrame:CGRectMake(0, 0, 50, 30)];
_item = [[UINavigationItem alloc] initWithTitle:nil];

_item.hidesBackButton = YES;

_item.leftBarButtonItem = activityItem;

_item.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
;

[_navBar pushNavigationItem:_item animated:YES];
于 2013-09-19T12:38:04.317 回答