2

次のコードが機能しない理由がわかりません。

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」ボタンは表示しません。

4

3 に答える 3

3

この動作に関連する別の問題を見つけました。

カスタムtitleViewnavigationItem.titleView = ...)を設定した場合、ナビゲーションアイテムは、スペースがない場合、最初のボタンを除いてボタンを非表示にすることがあります。

widthしたがって、カスタムのを制限するようにしてくださいtitleView

于 2013-03-10T07:34:00.000 に答える
2

rightBarButtonItemsは ios 5 にあります。問題はオブジェクト名newにあると思います。これを他の名前などに変更してくださいnewButton。new は in に使用されるキーワードであるためmemory allocationC++

于 2012-08-23T15:28:48.367 に答える
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];

他の誰かがこの問題に遭遇した場合に備えて、今すぐ投稿してください!

于 2012-08-23T15:28:54.257 に答える