我從github開始執行此項目。如何重新加載UIAlertView消息
它是自定義的AlertView。我明白它是如何工作的。修改爲我的項目,像這樣
Course1 - 一些產品的名稱, '1' - 是它的量。當我輸入正/負數量增加/減少時。但它只適用於我的變量(當我顯示它時,我加載到這個AlertView上,它是1)。如何通過更改var(金額)重新加載此警報視圖的消息。我無法理解。 在這裏我的代碼。
在我的課堂我叫警報查看該代碼
BlockAlertView *alert = [BlockAlertView alertWithTitle: title message:ac.acCount];
[alert setCancelButtonWithTitle:@"-" block:nil];
[alert setDestructiveButtonWithTitle:@"+" block:^{
int u = [ac.acCount intValue];
u++;
ac.acCount = [NSString stringWithFormat:@"%d", u];
NSLog(@"%d", u);
}];
[alert addButtonWithTitle:@"Ok" block:^{
NSMutableArray *container = [[NSMutableArray alloc] init];
[container addObject:title];
[container addObject:price];
[container addObject:bId];
[container addObject:ac.acCount];
[container addObject:depid];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotification" object:container];
}];
[alert show];
顯示方法只是繪製警報視圖使用參數從alertWithTitle需要:標題消息:ac.acCount。下面是代碼
+ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message
{
return [[[BlockAlertView alloc] initWithTitle:title message:message] autorelease];
}
這裏
- (id)initWithTitle:(NSString *)title message:(NSString *)message
{
NSLog(@"title - %@ message - %@", title, message);
if ((self = [super init]))
{
UIWindow *parentView = [BlockBackground sharedInstance];
CGRect frame = parentView.bounds;
frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5);
frame.size.width = background.size.width;
_view = [[UIView alloc] initWithFrame:frame];
_blocks = [[NSMutableArray alloc] init];
_height = kAlertViewBorder + 6;
if (title)
{
CGSize size = [title sizeWithFont:titleFont
constrainedToSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000)
lineBreakMode:UILineBreakModeWordWrap];
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)];
labelView.font = titleFont;
labelView.numberOfLines = 0;
labelView.lineBreakMode = UILineBreakModeWordWrap;
labelView.textColor = kAlertViewTitleTextColor;
labelView.backgroundColor = [UIColor clearColor];
labelView.textAlignment = UITextAlignmentCenter;
labelView.shadowColor = kAlertViewTitleShadowColor;
labelView.shadowOffset = kAlertViewTitleShadowOffset;
labelView.text = title;
[_view addSubview:labelView];
[labelView release];
_height += size.height + kAlertViewBorder;
}
if (message)
{
CGSize size = [message sizeWithFont:messageFont
constrainedToSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000)
lineBreakMode:UILineBreakModeWordWrap];
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)];
labelView.font = messageFont;
labelView.numberOfLines = 0;
labelView.lineBreakMode = UILineBreakModeWordWrap;
labelView.textColor = kAlertViewMessageTextColor;
labelView.backgroundColor = [UIColor clearColor];
labelView.textAlignment = UITextAlignmentCenter;
labelView.shadowColor = kAlertViewMessageShadowColor;
labelView.shadowOffset = kAlertViewMessageShadowOffset;
labelView.text = message;
[_view addSubview:labelView];
[labelView release];
_height += size.height + kAlertViewBorder;
}
_vignetteBackground = NO;
}
return self;
}
我試圖用這樣的
-(void)reloadAlertView: (NSString *) title: (NSString *) message{
[self initWithTitle:title message:message];
}
,並從我的課,把這個地方我顯示警報視圖。
[alert reloadAlertView: title: newMessage];
你可以發表一些你在這裏嘗試的代碼嗎?順便說一句你的問題不是很清楚,你究竟想要什麼。清楚地說明plz – mAc 2013-02-25 12:19:46
只需顯示您的代碼,絕對可以按照您的要求進行自定義。 – 2013-02-25 12:21:03
請注意,您不是使用'UIAlertView',而是使用不帶'UIAlertView'子類的替代品 - >,因此您的主題和問題文本至少是誤導性的。 – Till 2013-02-25 12:38:15