- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
请接受我早期的道歉,因为我对这个问题是全新的,所以我的术语可能不准确,希望你能理解我在问什么。
我在获取 UIBarButtonSystemItem 以在按下时将我带回不同 View 时遇到问题。我定义了一个带有 UIBarButtonSystemItem 的 UIToolBar,它可以完美地编译和运行。但是,当按下按钮时,应用会崩溃。
这是我用来定义 UIToolBar 和 UIButton 的代码:
//create toolbar using new
toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
[toolbar sizeToFit];
toolbar.frame = CGRectMake(0, 410, 320, 50);
//Add buttons
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(pressButton1:)];
然后我将 flexitem 添加到此并使用以下代码将按钮添加到数组:
//Use this to put space in between your toolbox buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, nil];
这是我摔倒的地方,我试图通过使用以下代码让按钮在按下时将我带到上一个 View :
-(void)pressButton1:(id)sender {
BMR_TDEE_CalculatorViewController *controller1 = [[BMR_TDEE_CalculatorViewController alloc] initWithNibName:@"BMR_TDEE_ViewController" bundle:nil];
controller1.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller1 animated:YES];
[controller1 release];
}
就像我说的,这只会让我的模拟器崩溃。它编译没有问题,但我猜代码从根本上是错误的,因为我是新手。解释清楚的任何帮助都会很棒 ;-)
谢谢大家
最佳答案
这个:
UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(pressButton1:)
应该是:
UIButton *button=[[UIButton alloc] init];
button.frame=CGRectMake(0, 0, 65, 32);
[button addTarget:self action:@selector(pressButton1:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
对于 (void)pressbutton
代码现在应该是:
-(IBAction)pressButton1:(id)sender {
BMR_TDEE_CalculatorViewController *controller = [[BMR_TDEE_CalculatorViewController alloc] initWithNibName:@"BMR_TDEE_CalculatorViewController" bundle:nil];
[self.navigationController presentModalViewController:controller animated:TRUE];
}
关于ios - 如何在 UIToolBar 上获取 UIBarButtonSystemItem 以将我带到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5304748/
我正在创建一个 UIToolbar,上面只放置了一个 UILabel。标签内容是动态的并且可以更改,我想将其集中在 UIToolbar 上。 有人知道 UIToolbar 左侧和右侧的确切边距大小吗?
我正在关注来自 here 的第二条提示.在本技巧中,两个 UIBarButtonItem 被放在一个 UIToolbar 中。最后,将 UIToolbar 添加到 UINavigationBar。现在
我有一个非常顽固的 UIToolbar,无论我尝试如何不同的方法,它都拒绝改变其高度。 我看过这个问题,但它对我不起作用 Is there a way to change the height of
如何制作垂直的 UIToolbar? 最佳答案 子类化 UIToolbar 并执行以下操作: CGFloat DegreesToRadian(CGFloat degrees) { return
是否可以在屏幕顶部放置一个 UIToolbar?示例应用程序类似于“日历”,右侧有“+”,左侧有“日历”按钮。 最佳答案 您可以将 UIToolbar 放置在任何地方。这只是一个 UI View 。
我需要创建一个使用图像作为背景的 UIToolbar 对象。大多数按钮也是图像,并且是矩形的。然而,有一个按钮是圆形的,并且与工具栏重叠,就像 Windows 任务栏上的“开始”按钮一样。见下文。 我
我想显示一个顶部有圆角的UIToolbar,最简单的方法是什么?工具栏未在窗口上对齐;它周围都有边距。谢谢! 最佳答案 非常简单。 首先 - 在 View Controller 的 .h 文件中有一个
我的 View 底部有一个 UIToolbar,并且此工具栏中有一个 UITextField。当我开始编辑此字段时,它隐藏在键盘后面。为了查看我输入的内容,我想在键盘出现时将工具栏向上移动(然后在完成
在我的应用程序中,我有一个工具栏,在某个时刻我想禁用或启用一些按钮。最简单的方法是什么?如何访问 UIToolbar 的 items 属性? 这是我的代码: -(void)addToolbar {
我有一个 UINavigationController,它被推送到 DetailsViewController。在这个DetailsViewController中,我想使用每个UINavigation
昨天下载了 IOS5 SDK,我用来将 UIToolbar 的背景设置为自定义图像的这段代码停止工作。如果我将目标设置为 IOS4.3 及以下,它仍然有效。 [self.bizToolbar inse
我正在尝试放置 UIToolBar在 UINavigationBar . UIToolbar* tempFontSizeToolBar = [[UIToolbar alloc] initWith
我有一个 UItableView,底部有一个工具栏。工具栏有两个按钮,分别是“水果”和“蔬菜”。单击它们将仅显示相应的类别。 我已经设法让显示功能正常工作,但我不知道如何在选择时将按钮设置为 sele
这个问题在这里已经有了答案: How to create this toolbar programmatically [closed] (6 个答案) 关闭 8 年前。 我试图在一个子类 ABPer
我想创建上面的用户界面。具体来说,一个更高的工具栏。但我需要以底层 UI(即内容 View )相应显示(即在工具栏下方)的方式这样做。 我熟悉 iOS 5 中新的 UIAppearance 选项。但是
UI问题在这里;我认为 UIToolbars 应该与状态栏融为一体?还是仅适用于 NavigationControllers? 最佳答案 UIToolBar 在顶部有一条默认的 1px 线(超出范围)
我有一个 UIToolbar。 如果我像这样创建一个 UIBarButton,它会起作用: UIBarButtonItem *button = [[UIBarButtonItem alloc] ini
我希望在用户单击按钮时(在我的例子中是当他们放大照片时)以编程方式将 UIToolbar 添加到 View 。 当我在 click 方法中创建工具栏并添加到 subview 时,它似乎工作正常但是如果
我的 View 上有一个 UITextView,并且可以通过按键盘工具栏上的完成按钮来关闭键盘。此按钮还对文本执行保存。在我的应用程序的最新版本之前,整个事情都运行得很好。我不明白发生了什么事。我怀疑
嘿伙计们,我正在尝试向 UIToolbar 添加文本,但有一个问题:我想更改字体并有 2 行文本(顶行较小,底行较大)。有什么想法如何做到这一点吗? 提前致谢! 最佳答案 您需要创建一个包含自定义 V
我是一名优秀的程序员,十分优秀!