任何人都可以帮助我...我有一个集合视图,显示从SQLite数据库中检索的数据。需要使用弹出窗口中的预定义列表更新集合视图单元格中的某些文本字段。
popover显示正确的值,我确实检索了所选的值,但我无法使用值更新collectionview中的文本字段。我假设我需要在启动segue时使用indexpath指定包含文本字段的单元格,但我不知道如何。
我使用以下方法启动弹出窗口:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if (textField.tag == 101) {
Global.Table = @"Access";
Global.Code = @"G";
Global.Request = @"Access";
[self performSegueWithIdentifier:@"PopUp" sender:self];
return NO;
}
else {
return YES;
}
}
popoff在tableview中选择正确的值后发送通知并被解除。
- (void)receivedNotification:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"scroller"]) {
if ([Global.Request isEqualToString:@"Access"]) {
NSLog(@"Returnvalue is %@",Global.Value);
//this is where the problem arises, I cannot access the text field to update the value, the return value is correct.
[self.collectionviewManagement selectItemAtIndexPath:0 animated:NO scrollPosition:0];
WDSCellManagement *cell = [_collectionviewManagement dequeueReusableCellWithReuseIdentifier:@"CellManagement" forIndexPath:0];
cell.AccessPersons.text = Global.Value;
}
}
}
非常感谢你的帮助!
答案 0 :(得分:0)
您使用委托模式,与任何视图控制器交互一样:
YourPopupController.h:
#import <UIKit/UIKit.h>
@class YourPopViewController;
@protocol YourPopupViewControllerDelegate <NSObject>
@optional
- (void)yourPopupViewController:(YourPopViewController *)yourPopupViewController
returnedValue:(NSString *)value;
@end
@interface YourPopupViewController : UITableViewController
@property (weak, nonatomic) id<YourPopupViewControllerDelegate> delegate;
@end
YourPopupViewController.m:
- (void)receivedNotification:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"scroller"]) {
if ([Global.Request isEqualToString:@"Access"]) {
if ([_delegate respondsToSelector:@selector(yourPopupViewController:returnedValue:)]) {
[_delegate yourPopupViewController:self
returnedValue:Global.Value];
}
}
}
}
然后在呈现视图控制器中符合YourPopupViewControllerDelegate
协议,并在调用委托方法时更新集合视图,从而解除弹出视图控制器。