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
发布于 2011-10-04 15:22:39
为什么不直接将委托传递给方法:
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];
}发布于 2011-10-04 15:26:32
您用于显示警报的代码看起来没有问题。检查您是否错误地将关键字self用作某个变量名称。
https://stackoverflow.com/questions/7644458
复制相似问题