开发者

Alertview error

    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:UIControlStateNorm开发者_开发百科al];

    //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]];              
}

this is the code that i used to display the alertview,but noproblem to show the alertview,but i cannot set the actions for the button in this alertview becz the deligate is set to nil.my problem is when i set the deligate to self the error shows that self undeclared.How to solve this issue? regards nipin


Why don't you just pass the delegate to the method:

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];
}


Your code for displaying alert looks fine. Check if you have by mistake used the keyword self as some variable name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜