gpt4 book ai didi

ios - 将日期选择器日期传回 View Controller 以在标签中显示日期

转载 作者:行者123 更新时间:2023-11-28 22:01:29 25 4
gpt4 key购买 nike

我已经研究了一堆关于如何做到这一点的问题,现在只是简短地提出来。

我有 ViewControllerA 和 ViewControllerB。

ViewControllerB 正在将 NSDateUIDatePicker 传回 ViewControllerA

我很好,直到尝试将 NSDate 作为标签放入它对应的 TableViewCell 中。

你能帮忙吗?谢谢!

ViewControllerA

- (void)addItemViewController:(EXEDurationPickerViewController *)controller didFinishEnteringItem:(NSString *)item {
NSLog(@"This was returned from ViewControllerB %@", item);
}

item 是从 ViewControllerB 中选取的日期。如何让它在相应的 TableViewCell 中显示为标签?

最佳答案

使用delegate传递日期或其他选项发送Notificaition

ViewControllerA 中添加这个

@interface ViewControllerA : UIViewController{
NSIndexPath *selectedIndexPath;
}
@end

-(void)viewDidLoad{

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNotification:)
name:@"dateSend"
object:nil];
}

- (void) receiveNotification:(NSNotification *) notification
{
NSString *item = notification.userInfo[@"date"];

// show for what cell you want to show
//keep selectedIndexPath as instance Variable
YourCell *cell = (YourCell *)[self.tableView cellForRowAtIndexPath:selectedIndexPath];
cell.label.text = item;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedIndexPath = indexPath;
}
//Post the notification fro `ViewControllerB`
- (void)addItemViewController:(EXEDurationPickerViewController *)controller didFinishEnteringItem:(NSString *)item {
NSLog(@"This was returned from ViewControllerB %@", item);


[[NSNotificationCenter defaultCenter] postNotificationName: @"TestNotification" object:nil userInfo:@{@"date":item}];
}

关于ios - 将日期选择器日期传回 View Controller 以在标签中显示日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24977792/

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