Я использую элемент выбора контактов для захвата строки, а затем передаю эту строку другому контроллеру представления, однако UILabel не обновляет данные (или любую другую строку).UILabel не обновляется при вызове метода делегата
В SlingViewController.m журналы, _taggedFriendsNames
успешно передается.
Возможно, проблема связана с тем, что контроллер приемного устройства пытается обновить метку на другом (SlingshotView
)? Я не думаю, что это так, так как я обновлял метки таким образом другими способами.
Ответ, вероятно, связан с обновлением UILabels в целом, но мне не повезло после поиска.
Вещи я проверил без успеха:
- Обновление от основного потока асинхронно
@synthesize
метка в SlingshotView- вызова
setDisplay
Включено потенциально соответствующий код ниже. Спасибо заранее за любые советы!
SlingViewController.m
-(void)updateFriendsPickedLabel:(id)sender {
NSLog(@"updateFriendsPickedLabel: %@", _taggedFriendsNames); // i see this
slingshotView.friendsPickedLabel.text = @"any string"; // i don't see this
}
SlingViewController.h
@class TBMultiselectController;
@class SlingshotView;
@interface SlingViewController : UIViewController
@property (nonatomic, readonly) SlingshotView *slingshotView;
@property(nonatomic) NSString *taggedFriendsNames;
//for friend picker
-(void)updateFriendsPickedLabel:(id)sender;
@end
MultiSelectViewController.m
- (IBAction) sendButton: (id) sender {
NSMutableString *myString = [[NSMutableString alloc]initWithString:@""];
for (int i=0; i < self.selectedContacts.count; i++) {
Contact *myContact = self.selectedContacts[i];
[myString appendString:[NSString stringWithFormat:@"%@ %@ ", myContact.firstName, myContact.lastName]];
}
SlingViewController *svc = [[SlingViewController alloc] init];
svc.taggedFriendsNames = myString;
[svc updateFriendsPickedLabel:self];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
MultiSelectViewController.h
@protocol TBMultiselectControllerDelegate;
@class SlingViewController;
@interface TBMultiselectController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchDisplayDelegate, TBContactsGrabberDelegate>
@property (nonatomic, assign) id<TBMultiselectControllerDelegate> delegate;
- (IBAction)sendButton: (id) sender;
@end
@protocol TBMultiselectControllerDelegate <NSObject>
-(void)updateFriendsPickedLabel:(id)sender;
@end
SlingshotView.h
@property (strong, nonatomic) UILabel *friendsPickedLabel;
SlingshotView.m
@synthesize friendsPickedLabel;
...
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect imageFrame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
contentView = [[UIView alloc] initWithFrame:frame];
[contentView setBackgroundColor:[UIColor whiteColor]];
[contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self addSubview:contentView];
self.friendsPickedLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, screenRect.size.height/2-100, screenRect.size.width-20, 200)];
self.friendsPickedLabel.shadowColor = [UIColor darkGrayColor];
self.friendsPickedLabel.numberOfLines = 0;
self.friendsPickedLabel.shadowOffset = CGSizeMake(0.5, 0.5);
self.friendsPickedLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
[self.friendsPickedLabel setTextAlignment:NSTextAlignmentLeft];
self.friendsPickedLabel.textColor = [UIColor whiteColor];
self.friendsPickedLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:24];
[contentView addSubview:self.friendsPickedLabel];
бы предположить, либо вид или метка равна нулю, так как этот метод вызывается. Попробуйте выполнить регистрацию и посмотрите, что вы получаете: 'NSLog (@"% @% @ ", slingshotView, friendsPickedLabel);' – JeffN
Вы вызываете метод делегата в новом экземпляре 'SlingViewController', который вы создаете локально, а затем освобождаетесь на конец метода. Это уже не то, что у вас уже есть. – dan