尝试在基于分割视图的应用程序中的detailviewcontroller工具栏的右侧添加按钮。我用灵活的空间把它放在右边。在肖像中,它可以很好地工作,但是在横向(当菜单按钮消失时),按钮会移动,因此其中一半离开了屏幕。如何在UISplitViewController工具栏的右侧添加一个按钮?
下面是相关的代码(在DetailViewController.m
):
- (void) viewDidLoad
{
// initialize toolbar
toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 768, 44)];
titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(284, 3, 200, 35)];
titleLabel.text = @"Title & Location";
titleLabel.textAlignment = UITextAlignmentCenter;
[toolbar addSubview: titleLabel];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle: @"Add Event" style: UIBarButtonItemStyleDone target: rootController action: @selector(parseDone)];
NSArray *buttonArray = [NSArray arrayWithObjects: flexibleSpace, doneButton, nil];
[toolbar setItems: buttonArray];
[doneButton release];
[flexibleSpace release];
[self.view addSubview: toolbar];
}
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem
{
NSMutableArray *itemsArray = [toolbar.items mutableCopy];
[itemsArray insertObject: barButtonItem atIndex: 0];
[toolbar setItems:itemsArray animated:NO];
}
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem
{
NSMutableArray *itemsArray = [toolbar.items mutableCopy];
[itemsArray removeObject:barButtonItem];
[toolbar setItems:itemsArray animated:NO];
[itemsArray release];
}
这个问题很可能是由于autoresizing掩码。您可能会检查设置并确保它们是您的意思。 – PengOne 2011-06-01 21:47:17
我过去也遇到过这个问题,并且我以某种方式修复了它,但是我的记忆就像是一个漏勺。 – 2011-06-01 21:47:40
此外,您提出了14个问题并接受了0个答案。您可能希望回到以前的问题,并接受(单击旁边的复选标记)解决问题的答案。通过这样做,您成为SO社区的积极成员,并且更有可能鼓励人们花时间在未来尝试帮助您。 – PengOne 2011-06-01 21:49:13