У меня есть дизайн пользовательского alerview для моего проекта. Я создаю отдельные файлы viewcontroller (.h и .m) с помощью @protocol для делегатов, чтобы получить ответ на нажатие кнопки alertview. Я создал объект для контроллера представления (настраиваемый alertview, который я создаю с пользовательским делегатом). и я рассматриваю пользовательское alertview в каждом из других классов. Он работает как обычный UIAlertview.Пользовательские Alertview с делегатами без раскадровки
Но проблема возникает, когда я показываю alertview, а затем нажимаю кнопку «домой» и возвращаюсь в мое приложение, чтобы его заморозить в ios7 и в ios6 получить сбой.
Что мне делать, чтобы исправить эту проблему. Он (просмотр предупреждений) должен работать нормально, когда я вернусь в свое приложение. Пожалуйста, дайте свои идеи исправить это.
Я не могу найти, как яблоко по умолчанию UIAlertview работает, когда в одном и том же режиме (dipaly alertview и входить в фон и rentun в приложение, отображаемое alertview отлично работает).
я м не использовать UIAlertvie
alert_cupboard = [[UIAlertView Alloc] initWithTitle: @ "Название" Сообщение: @ "сообщение" делегат: само cancelButtonTitle: ноль otherButtonTitles: @ "Да", @ "Нет", ноль]; alert_cupboard.tag = 0; [alert_cupboard show];
Для этого у меня есть дизайн в моем коде для создания пользовательского Alertview
CustomAlertView.h
@protocol AlertViewprotocal <NSObject>
@required
- (void)AlertSuccess:(id)result;
- (void)AlertFailure:(id)result;
@end
@interface CustomAlertView : UIViewController
{
UIView *view_alert;
UIImageView *img_alert_bg;
UIView *view_alert_popup;
UILabel *lbl_alert_title;
UILabel *lbl_alert_message;
UILabel *lbl_sep_horizontal;
UILabel *lbl_sep_vertical;
UIButton *btn_alert_OK;
UIButton *btn_alert_yes;
UIButton *btn_alert_no;
}
@property(nonatomic,weak)id<AlertViewprotocal> CustomAlertdelegate;
+(CustomAlertView *)singleton;
-(void)showAlertView:(UIViewController *)rootViewController:(NSInteger)option :(NSString *)message :(NSInteger)tag;
-(IBAction)action_alert_yes:(id)sender;
-(IBAction)action_alert_hide:(id)sender;
@end
CustomAlertView.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
float height=[UIScreen mainScreen].bounds.size.height;
float width=[UIScreen mainScreen].bounds.size.width;
view_alert=[[UIView alloc]initWithFrame:CGRectMake(0, 0,width , height)];
img_alert_bg=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,width , height)];
[img_alert_bg setImage:[UIImage imageNamed:@"pop_up_bg.png"]];
[view_alert addSubview:img_alert_bg];
view_alert_popup=[[UIView alloc]initWithFrame:CGRectMake(IS_IPAD ? (234): 10, (height-156)/2, IS_IPAD ? (300):(width-(10*2)) , 156)];
[view_alert_popup setBackgroundColor:[UIColor whiteColor]];
view_alert_popup.layer.cornerRadius= 10.5; //IS_IPAD ?8.2:
lbl_alert_title=[[UILabel alloc]initWithFrame:CGRectMake(20, 5, 260, 35.0)];
[lbl_alert_title setTextColor:[UIColor blackColor]];
[lbl_alert_title setBackgroundColor:[UIColor clearColor]];
[lbl_alert_title setText:@"Title"];
lbl_alert_title.textAlignment = UITextAlignmentCenter;
lbl_alert_title.font = [UIFont fontWithName:@"Helvetica" size: 18.0]; //IS_IPAD ? 34.0 :
[view_alert_popup addSubview:lbl_alert_title];
lbl_alert_message=[[UILabel alloc]initWithFrame:CGRectMake(20, lbl_alert_title.frame.size.height, view_alert_popup.frame.size.width-(20*2), 70)];
[lbl_alert_message setTextColor:[UIColor blackColor]];
[lbl_alert_message setBackgroundColor:[UIColor clearColor]];
lbl_alert_message.font = [UIFont fontWithName:@"Helvetica" size: 16.0]; //IS_IPAD ? 34.0 :
lbl_alert_message.textAlignment = UITextAlignmentCenter;
lbl_alert_message.numberOfLines=3;
lbl_alert_message.lineBreakMode=UILineBreakModeWordWrap;
[view_alert_popup addSubview:lbl_alert_message];
lbl_sep_horizontal=[[UILabel alloc]initWithFrame:CGRectMake(0, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height), view_alert_popup.frame.size.width, 1.0)];
[lbl_sep_horizontal setBackgroundColor:[UIColor lightGrayColor]];
[view_alert_popup addSubview:lbl_sep_horizontal];
lbl_sep_vertical=[[UILabel alloc]initWithFrame:CGRectMake(150, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height), 1.0, 50.0)];
[lbl_sep_vertical setBackgroundColor:[UIColor lightGrayColor]];
[view_alert_popup addSubview:lbl_sep_vertical];
btn_alert_yes=[[UIButton alloc]initWithFrame:CGRectMake(0, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height+10), 150, 30.0)];
[btn_alert_yes setBackgroundColor:[UIColor clearColor]];
[btn_alert_yes setTitleColor:[UIColor colorWithRed:(204.0/255.0) green:(50.0/255.0) blue:(100.0/255.0) alpha:1.0] forState:UIControlStateNormal];
[btn_alert_yes.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size: 16.0]];
[btn_alert_yes setTitle:@"Yes" forState:UIControlStateNormal];
//[btn_alert_yes.titleLabel setText:@"Yes"];
[btn_alert_yes addTarget:self action:@selector(action_alert_yes:) forControlEvents:UIControlEventTouchUpInside];
[view_alert_popup addSubview:btn_alert_yes];
btn_alert_no=[[UIButton alloc]initWithFrame:CGRectMake(150, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height+10), 150, 30.0)];
[btn_alert_no setBackgroundColor:[UIColor clearColor]];
[btn_alert_no setTitleColor:[UIColor colorWithRed:(204.0/255.0) green:(50.0/255.0) blue:(100.0/255.0) alpha:1.0] forState:UIControlStateNormal];
[btn_alert_no.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size: 16.0]];
[btn_alert_no setTitle:@"No" forState:UIControlStateNormal];
//[btn_alert_no.titleLabel setText:@"No"];
[btn_alert_no addTarget:self action:@selector(action_alert_hide:) forControlEvents:UIControlEventTouchUpInside];
[view_alert_popup addSubview:btn_alert_no];
btn_alert_OK=[[UIButton alloc]initWithFrame:CGRectMake(0, (lbl_alert_message.frame.origin.y+lbl_alert_message.frame.size.height+10), 300, 30.0)];
[btn_alert_OK setBackgroundColor:[UIColor clearColor]];
[btn_alert_OK setTitleColor:[UIColor colorWithRed:(204.0/255.0) green:(50.0/255.0) blue:(100.0/255.0) alpha:1.0] forState:UIControlStateNormal];
[btn_alert_OK.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size: 16.0]];
[btn_alert_OK setTitle:@"OK" forState:UIControlStateNormal];
//[btn_alert_OK.titleLabel setText:@"OK"];
[btn_alert_OK addTarget:self action:@selector(action_alert_hide:) forControlEvents:UIControlEventTouchUpInside];
[view_alert_popup addSubview:btn_alert_OK];
[view_alert addSubview:view_alert_popup];
[self.view addSubview:view_alert];
}
return self;
}
+(CustomAlertView *)singleton
{
if (shared)
{
shared=nil;
}
shared = [[CustomAlertView alloc] init];
return shared;
}
-(void)showAlertView:(UIViewController *)rootViewController:(NSInteger)option :(NSString *)message :(NSInteger)tag
{
lbl_alert_message.text=message;
view_alert.tag=tag;
if (option==1)
{
[btn_alert_OK setHidden:NO];
btn_alert_OK.tag=tag;
[btn_alert_yes setHidden:YES];
[btn_alert_no setHidden:YES];
[lbl_sep_horizontal setHidden:NO];
[lbl_sep_vertical setHidden:YES];
}
else
{
[btn_alert_OK setHidden:YES];
[btn_alert_yes setHidden:NO];
[btn_alert_no setHidden:NO];
[lbl_sep_horizontal setHidden:NO];
[lbl_sep_vertical setHidden:NO];
btn_alert_yes.tag=tag;
}
view_alert_popup.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[UIView animateWithDuration:0.4/1.5 animations:^
{
view_alert_popup.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished)
{
[UIView animateWithDuration:0.4/2 animations:^
{
[rootViewController.view addSubview:self.view];
view_alert_popup.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
} completion:^(BOOL finished)
{
[UIView animateWithDuration:0.4/2 animations:^{
view_alert_popup.transform = CGAffineTransformIdentity;
}];
}];
}];
}
-(IBAction)action_alert_yes:(id)sender
{
[self.view removeFromSuperview];
[self.CustomAlertdelegate AlertSuccess:view_alert];
}
-(IBAction)action_alert_hide:(id)sender
{
[self.view removeFromSuperview];
[self.CustomAlertdelegate AlertFailure:view_alert];
}
меня использовать логотий alertview в другом моего контроллере зрения
HomeView.h
@interface HomeScreen :UIViewController <AlertViewprotocal> //CustomAlertView
{
CustomAlertView *alert;
}
HomeView.m
-(void)viewWillAppear:(BOOL)animated
{
alert=[CustomAlertView singleton];
alert.CustomAlertdelegate=self;
}
- (void)viewWillDisappear:(BOOL)animated
{
alert.CustomAlertdelegate=nil;
}
-(IBAction)action_addRemove:(id)sender
{
UIButton *btn=sender;
self.add_row=btn.tag;
[alert showAlertView:self :2 :@"message" :0];
}
- (void)AlertSuccess:(id)result
{
UIView *vw=result;
NSLog(@"Success tag:%d",vw.tag);
switch (vw.tag)
{
case 0:
{
[self remove];
}
break;
case 1:
{
[self add];
}
break;
default:
break;
}
}
- (void)AlertFailure:(id)result
{
UIView *vw=result;
NSLog(@"Failure tag:%d",vw.tag);
}
Я получил
- [ __NSArrayM action_alert_yes:]: непризнанный селектор, отправленный в экземпляр 0xc135350 Трассировка стека: NSInvalidArgumentException
какой вид аварии вы испытываете? можете ли вы добавить трассировку стека? – Daniele
Добавить контрольную точку исключения и показать нам, где ее сбой –