在UIAlertView中更改取消button的位置?

我注意到,当我从我的iPhone主屏幕上删除一个应用程序,出现的警报视图显示在左边的删除button和在右边的取消。 但是,当我使用UIAlertView在我的应用程序中构build一个删除function时,这些button似乎只显示左边的取消和右边的删除。

我想我的应用程序与操作系统一致,但我不知道如何使取消button首先出现。 有人知道吗?

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete Song" message:@"Are you sure you want to delete this song? This will permanently remove it from your database." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil]; 

我尝试设置alert.cancelButtonIndex = 1,但是没有效果。

苹果在主屏幕上使用警报视图的一个可能的原因是,它曾经要求用户评价他们正在删除的应用程序(不再是)。 他们可能会使“取消”button变成浅色,因为这被认为是一种破坏性行为(删除应用程序及其数据)。

我想你可以颠倒标题( cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil )和处理点击这些button相反方向(不知道苹果是否也一样)。 虽然这会有些尴尬; 如何使用一个行动表呢?

啊,我只是想出了如何改变这一点。 cancelButtonTitle参数是可选的,所以你可以在你想要的任何位置添加一个自定义button,然后指定为取消button,如下所示:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete Song" message:@"Are you sure you want to delete this song? This will permanently remove it from your database." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Delete", @"Cancel", nil]; alert.cancelButtonIndex = 1; 

这将删除button的左侧,取消button在右侧,并突出显示取消button。