简体   繁体   中英

Is there a reason I can't pass null as the title to the UIActionSheet constructor in MonoTouch?

I'm trying to make a delete confirmation action sheet like what you see in OmniGraffle, GarageBand, and several other apps. I want an action sheet with no title and one big red delete button.

In reading the documentation for the constructor of UIActionSheet, it says:

title

A string to display in the title area of the action sheet. Pass nil if you do not want to display any text in the title area.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html

However, if I do this in MonoTouch:

UIActionSheet actionSheet = new UIActionSheet(
    null, 
    null,
    null,
    "Delete"
);

I get a NullArgumentException . Same if I try to workaround by passing in a dummy string and then do actionSheet.Title = null; . Passing in string.Empty works fine, but gives me extra space above the button I do not want.

So:

  1. Is there a reason for this behavior, or is it just a MonoTouch bug?
  2. Is there a workaround I can use to get the look and feel I want?

在此输入图像描述

This (with a big red delete button) can't be too hard in MonoTouch!

But I'm stuck with this:

在此输入图像描述

See the extra space at the top? What do I do?

Many thanks for filling the bug report. This has been fixed for future releases of MonoTouch.

Until then you should be able to replace this:

UIActionSheet actionSheet = new UIActionSheet(
    null, 
    null,
    null,
    "Delete"
);

with

 UIActionSheet actionSheet = new UIActionSheet ();
 actionSheet.DestructiveButtonIndex = actionSheet.AddButton ("Delete");

Let me know if this does not cover the use case you had in mind and I'll try to find another workaround.

According to teh Apple documentation, passing nil for the title is perfectly valid .

This sounds like a bug in the MonoTouch binding of the UIActionSheet designated initializer. I searched the Xamarin Bugzilla and this does not seem to be a known issue.

I would file a bug, and link to this question, should be an easy fix. They may even be able to provide you with a workaround ;-)

Yes, there is. Null is not part of objective-c. You need to use Nil. Look closely at the documentation you've posted.

The difference between them is that null is not an object and comes from c, while nil is an object and is a part of the objective-c superset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM