gpt4 book ai didi

ios - 如何重新加载 UIAlertView 消息

转载 作者:行者123 更新时间:2023-11-29 04:06:48 25 4
gpt4 key购买 nike

我从 github 获取了这个项目.

这是自定义的AlertView。我明白它是如何运作的。为我的项目修改了它,就像这样

enter image description here

Course1 - 某些产品的名称,“1” - 是其数量。当我输入正/负金额增加/减少时。但它只适用于我的变量(当我显示它时,我将其加载到这个 AlertView 上,并且它是 1)。如何通过更改 var(金额)重新加载此警报 View 的消息。我不明白。这是我的代码。

在我的类(class)中,我通过此代码调用警报 View

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

Show 方法只是使用来自alertWithTitle: title message:ac.acCount 的参数绘制警报 View 。这是代码

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

并从我的类(class)中调用它,我在类(class)中显示警报 View 。

[alert reloadAlertView: title: newMessage];

最佳答案

您需要在 CustomAlertView.h 中引用新标签

@property (nonatomic, strong) IBOutlet UILabel *mylab;

然后就可以通过CustomAlertView.h类的对象来获取这个标签的属性

BlockAlertView *alert ...;
alert.mylab.text = @"hello";

关于ios - 如何重新加载 UIAlertView 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15066657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com