gpt4 book ai didi

iOS - 在选择器 View 中访问文本变量以在通知声音名称中使用

转载 作者:行者123 更新时间:2023-11-29 12:13:49 25 4
gpt4 key购买 nike

我有第一种安排本地通知的方法:

- (void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = fireDate;
notification.category = @"Alarm";
notification.soundName = @"Pager.caf";
[[UIApplication sharedApplication] scheduleLocalNotification: notification];
}

然后,我创建了一个 Picker View,用户可以使用此方法在列表中选择警报音:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *resultString = _alarmNames[row];
_alarmToneText.text = resultString;
}

现在,我想编辑 scheduleNotification 方法来调用选择器 View 中的文本值,即 resultString 并将其放入 notification.soundName。

代码如下所示:

notification.soundName = resultString;

最佳答案

@interface ViewController ()
{
NSString *soundName;
}
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
soundName = @"";
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
soundName = _alarmNames[row];
}

- (void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{
if (![soundName isEqualToString:@""]) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = fireDate;
notification.category = @"Alarm";
notification.soundName = soundName;
[[UIApplication sharedApplication] scheduleLocalNotification: notification];
} else {
// Show alert for select sound
}

}

无需为选定的声音文件名显示 TextFied。 [这是有史以来的最佳做法。]

关于iOS - 在选择器 View 中访问文本变量以在通知声音名称中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32494348/

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