我不确定以下代码无效的原因:
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"New" style:UIBarButtonItemStyleBordered target:self action:@selector(newClicked:)];
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:newButton, shareButton, nil];
它只在导航栏上显示“newButton”UIBarButtonItem,而不是“shareButton”按钮。
答案 0 :(得分:2)
rightBarButtonItems 位于ios 5中。
我认为问题在于对象名称new
,请将此更改为任何其他名称,例如newButton
或类似名称。
因为new是memory
allocation
C++
使用的关键字
答案 1 :(得分:1)
看起来问题与疑问代码后面的代码有关:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:@"Marker Felt" size:26.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor whiteColor];
label.text=self.title;
self.navigationItem.titleView = label;
[label release];
现在发布此内容以防其他人遇到此问题!