Luke
Luke

Reputation: 3655

iPhone app InputAccessoryView isn't appearing on iPad

I'm using Monotouch to develop an app for the iPhone.

In my iPhone only app, I have an InputAccessoryView appear whenever the user selects a textfield. The accessory view provides buttons which aid the user (undo/redo etc).

It works fantastically on the simulator and on iPhone devices.

However, out of the blue, the Input Accessory View is not appearing on the iPad. I've made no changes to the code regarding the views; I've even rolled back to a version that I know displayed the accessory view correctly.

I was wondering if anyone else has come across this behaviour before / would know why this is happening?

EDIT

I've seen this accross all of my iphone projects running on the ipad. I made a fresh project which only contains 1 view, a UITextField and override the Input Accessory View and I'm still seeing nothing.

Code I'm using to test the override of the input view is:

public override UIView InputAccessoryView
{
   get
   {
      UIView view = new UIView(new RectangleF(0,0,320,30));
      view.BackgroundColor = UIColor.Blue;
      return view;
   }
}

Nothing too complex, on the iPhone just returns a blue bar above the keyboard.

I've reinstalled Mono, MonoDevelop, Monotouch and the iOS SDK multiple times to no avail. Apps that I've downloaded from the store still show the Input Accessory View, so I'm beginning to wonder if it's an issue with my Monotouch/iOS SDK combo? I'm using Monotouch 3.1.3 personal and 4.1 iOS SDK - version 2.6 of Mono. I'm going to try updating to version 2.8 of Mono.

The thing I don't understand is why it would work previously then all of a sudden just stop working?

When I'm deploying the code on the iPad, I'm selecting "Rebuild all", then uploading to the device. It doesn't matter if I pick either Release/Debug as a build, both yield the same result.

EDIT 2

If I subclass a UITextField and override the InputAccessoryView within that subclass, then the view appears on the iPad. This means that the InputAccessoryView which is being overriden in the View class isn't being assigned to the Textfield on the ipad.

EDIT 3 It would appear this is fixed in iOS 4.2 with Monotouch 3.2 !

Upvotes: 1

Views: 1604

Answers (3)

Doid
Doid

Reputation: 21

I had the same issue where a UITextView contained within a UIView would show the accessory bar on the simulator but not on the iPhone or iPad.

I'm doing some strange things with BeginFirstResponder to allow tapping anywhere in the larger parent area (containing a label and the text field) and activating the contained field and suspected this was involved. I added code in the parent UIView to override the InputAccessoryView and have it return the the value from the child UITextView and this fixed.

I suspect that Monotouch has an issue routing the event to the wrong object and my fix resolved it.

pseudo code:

public class ParentView : UIView
{
  UILabel Label;
  MyTextView Text;

 /*Magic line here that fixed the problem */
 public override UIView InputAccessoryView {get{return Text.InputAccessoryView;}}
}

public class MyTextView : UITextView
{
  UIView Accessory;

  public override UIView InputAccessoryView {get{return Accessory;}}
}

Upvotes: 2

miguel.de.icaza
miguel.de.icaza

Reputation: 32694

How are you showing your accessory view?

Can you try keeping a reference to the view?

Try this, and let me know if this fails:

public class Foo { static UIView track; }

And then when you create your view, stick it in that global:

Foo.track = new MyAccessoryView ()

Upvotes: 1

user8472
user8472

Reputation: 3326

My first suggestion is to reset the device in iTunes. You may have done so already, but just in case you did not, please do it first (since it's quick and easy to do).

If that didn't help: To identify if it is a problem with Monotouch and/or the iOS SDK could you repeat what you did above using only Cocoa Touch?

I.e., start a View-based app in XCode, add one UITextField in Interface Builder and connect it to the controller. Here is a corresponding Objective-C code to do it:

Instance variables in your controller (add to the @interface section in the <controllername>.h file):

IBOutlet UITextField *text;
UIView *accessory;

Hook up the UITextField in Interface Builder with the text outlet and then add the following implementation of viewDidLoad to the controller (the @implementation section in the <controllername>.m file):

- (void)viewDidLoad {
    accessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
    [accessory setBackgroundColor:[UIColor blueColor]];
    [text setInputAccessoryView:accessory];
    [super viewDidLoad];
}

If this displays the blue bar correctly, the problem is with the setup of Monotouch. If it does not, it is an issue with your device.

Upvotes: 2

Related Questions