objective-c如何容纳 8 个按钮在 UIAlertView

发布时间: 2016/10/2 9:24:40
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

enter image description here我在 alertview ve 问题。最初,我在我的 alertview 6 按钮。然后我不得不将两个按钮添加到我的 alertview。当我添加两个按钮,帧大小成为一个问题。

请参阅屏幕截图。

-(IBAction)FilterButton:(id)sender
{
    UIAlertView *alert1 = [[UIAlertView alloc]
                           initWithTitle:nil
                           message:@"\n\n\n\n\n"
                           delegate:self
                           cancelButtonTitle:@"Cancel"
                           otherButtonTitles:@"Customer",@"Contact",@"Lead",@"Team Member",@"Ex-Team Member",@"Inactive Customer",@"All Contacts",nil];

    [alert1 show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {

        case 1:
        {
            qsql = [NSString stringWithFormat:@"select * from pu_Contacts where ContactType = 'CUS' and isDeleted ='0';"];
            [self selected];
            break;            
        }
        case 2:
        {
            qsql = [NSString stringWithFormat:@"select * from pu_Contacts where ContactType = 'CT' and isDeleted ='0';"];
            [self selected];
            break;            
        }
        case 3:
        {
            qsql = [NSString stringWithFormat:@"select * from pu_Contacts where ContactType = 'LD' and isDeleted ='0';"];
            [self selected];
            break;            
        }       
        case 4:
        {
            qsql = [NSString stringWithFormat:@"select * from pu_Contacts where ContactType = 'TM' and isDeleted ='0';"];
            [self selected];
            break;
        }
        case 5:
        {
            qsql = [NSString stringWithFormat:@"select * from pu_Contacts where ContactType = 'ETM' and isDeleted ='0';"];
            [self selected];
            break;
        }
        case 6:
        {
            qsql = [NSString stringWithFormat:@"select * from pu_Contacts where ContactType = 'INACUS' and isDeleted ='0';"];
            [self selected];
            break;
        }
        case 7:
        {
            qsql = [NSString stringWithFormat:@"select * from pu_Contacts where isDeleted ='0';"];
            [self selected];
            break;
        }
    }
}

解决方法 1:

我测试了您创建的代码,添加按钮在 Alertview 中的却很难管理它,所以我建议你使用 UIActionsheet 像惨叫代码:-

  UIActionSheet *MultipleAcions = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:nil otherButtonTitles:@"Customer",@"Contact",@"Lead",@"Team Member",@"Ex-Team Member",@"Inactive Customer",@"All Contacts",nil];
    MultipleAcions.actionSheetStyle = UIActionSheetStyleDefault;
    [MultipleAcions showInView:self.view];

它的外观林科贝娄截图:-

enter image description here

你可以得到每个按钮的索引使用波纹管 UIActionsheet 的委托:-

-(void)actionSheet:(UIActionSheet *)actionSheets clickedButtonAtIndex:(NSInteger)buttonIndex
官方微信
官方QQ群
31647020