首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Alertview错误

Alertview错误
EN

Stack Overflow用户
提问于 2011-10-04 15:17:54
回答 2查看 182关注 0票数 0
代码语言:javascript
复制
    UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Share"
                                                        message:message
                                                       delegate:delegate
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Notes", @"Bookmark", @"Facebook",@"Twitter",@"Email", nil] autorelease];
    [theAlert show];




    //Set View of Button Cancel at index 1 in AlertView.
    //[[[theAlert subviews] objectAtIndex:1] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_Popup.png"]]];
    //[[[theAlert subviews] objectAtIndex:1] setBackgroundColor:[UIColor redColor]];
    //[[[theAlert subviews] objectAtIndex:1] setShadowColor:[UIColor clearColor]];

    //Set View of Button at index 2 in AlertView.
    [[[theAlert subviews] objectAtIndex:1] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_Popup.png"]]];
    //[[[theAlert subviews] objectAtIndex:2] setBackgroundColor:[UIColor blueColor]];
    [[[theAlert subviews] objectAtIndex:1] setShadowColor:[UIColor clearColor]];
    //[[[theAlert subviews] objectAtIndex:2] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

    //Set View of Button at index 3 in AlertView.
    [[[theAlert subviews] objectAtIndex:2] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_Popup.png"]]];
    //[[[theAlert subviews] objectAtIndex:3] setBackgroundColor:[UIColor orangeColor]];
    [[[theAlert subviews] objectAtIndex:2] setShadowColor:[UIColor clearColor]];
    //[[[theAlert subviews] objectAtIndex:3] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

    //Set View of Button at index 4 in AlertView.
    [[[theAlert subviews] objectAtIndex:3] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_Popup.png"]]];
    //[[[theAlert subviews] objectAtIndex:4] setBackgroundColor:[UIColor greenColor]];
    [[[theAlert subviews] objectAtIndex:3] setShadowColor:[UIColor clearColor]];
    //[[[theAlert subviews] objectAtIndex:4] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

    //Set View of Button at index 5 in AlertView.
    [[[theAlert subviews] objectAtIndex:4] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_Popup.png"]]];
    //[[[theAlert subviews] objectAtIndex:5] setBackgroundColor:[UIColor greenColor]];
    [[[theAlert subviews] objectAtIndex:4] setShadowColor:[UIColor clearColor]];
    //[[[theAlert subviews] objectAtIndex:5] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

    //Set View of Button at index 6 in AlertView.
    [[[theAlert subviews] objectAtIndex:5] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button_Popup.png"]]];
    //[[[theAlert subviews] objectAtIndex:6] setBackgroundColor:[UIColor greenColor]];
    [[[theAlert subviews] objectAtIndex:5] setShadowColor:[UIColor clearColor]];
    //[[[theAlert subviews] objectAtIndex:6] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

    UILabel *theTitle = [theAlert valueForKey:@"_titleLabel"];
    [theTitle setFont:[UIFont fontWithName:@"Helvetica" size:16]];
    [theTitle setTextAlignment:UITextAlignmentLeft];

    UIImage *theImage = [UIImage imageNamed:@"Popup.png"];
    CGSize theSize = [theAlert frame].size;

    UIGraphicsBeginImageContext(theSize);
    [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
    theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [[theAlert layer] setContents:[theImage CGImage]];              
}

这是我用来显示警报视图的代码,但显示警报视图没有问题,但我不能为此警报视图中的按钮设置操作,因为deligate设置为nil.my问题是当我将deligate设置为self时错误显示self undeclared.How解决此问题?关于nipin

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-04 15:22:39

为什么不直接将委托传递给方法:

代码语言:javascript
复制
void DisplayAlert(NSString* title, NSString* message, id delegate) {

    UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Share"
                                                        message:message
                                                       delegate:delegate
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Notes", @"Bookmark", @"Facebook",@"Twitter",@"Email", nil] autorelease];
    [theAlert show];
}
票数 0
EN

Stack Overflow用户

发布于 2011-10-04 15:26:32

您用于显示警报的代码看起来没有问题。检查您是否错误地将关键字self用作某个变量名称。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7644458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档