【问题标题】:UIToolbar button crashes app when pressed按下 UIToolbar 按钮会使应用程序崩溃
【发布时间】:2014-03-10 23:04:21
【问题描述】:

每当我打开 UITextView 时,我都会在键盘上设置一个工具栏。这是我当前的代码。

UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:[[UIBarButtonItem alloc]initWithTitle:@"Done"   style:UIBarButtonItemStyleDone target:self action:@selector(done:)],nil];
[numberToolbar sizeToFit];
self.yourTextView.inputAccessoryView = numberToolbar;

但是,当我按下按钮时,应用程序崩溃了。如何使按钮在按下时将光标切换到另一个 UITextView?

【问题讨论】:

  • 你能发布错误吗?
  • 您是否实现了您指定为按钮操作的- (void)done:(id)sender {} 方法?
  • 是的,这就是问题所在,@rmaddy。您能否提供一个解决方案,说明如何使按钮将光标切换到另一个 UITextView?
  • 这是一个全新的问题。
  • 在提出新问题之前,先做一些研究。你不是第一个问这个问题的人。无需重复。

标签: ios iphone uitoolbar


【解决方案1】:

使用此代码,如果不需要,请不要传递参数

UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:[[UIBarButtonItem alloc]initWithTitle:@"Done"   style:UIBarButtonItemStyleDone target:self action:@selector(done)],nil];
[numberToolbar sizeToFit];
self.yourTextView.inputAccessoryView = numberToolbar;

-(void)done

{

NSLog(@"hello");

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多