2

我正在选择一个 Facebook 朋友。我想在启动 facebook 朋友选择器的文本字段中显示 facebook 朋友的名字。

谢谢!

此外,获取用户字符串名称和选择要发送对象的朋友之间有区别吗?因为这就是用户要做的事情。因此,我需要显示用户名的字符串值,但我还必须将对象与该用户相关联。

-(IBAction)cancelList;
-(IBAction)submitList;
-(IBAction)datePicker;

@property (strong, nonatomic) IBOutlet UITextField *listFieldText;
@property (strong, nonatomic) IBOutlet UITextField *dateFieldText;
@property (strong, nonatomic) IBOutlet UITextField *wallPostText;
@property (strong, nonatomic) IBOutlet UITextField *friendsName;
@property (retain, nonatomic) UIDatePicker *pick;
@property (strong, nonatomic) UIImage *profilePic;

@property (retain, nonatomic) PF_FBFriendPickerViewController *friendPickerController;

执行:

- (void)textFieldDidBeginEditing:(UITextField *)sender
{
    sender.delegate = self;
    if([sender isEqual:dateFieldText])
    {
        UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
                                       initWithTitle:@"Save Date"
                                       style:UIBarButtonItemStyleDone
                                       target:self
                                       action:@selector(datePicker)];
        self.navigationItem.rightBarButtonItem = doneButton;
        pick = [[UIDatePicker alloc] init];
        [pick setFrame:CGRectMake(0,200,320,120)];
        //[pick addTarget:self action:@selector(done) forControlEvents:UIControlEventValueChanged];
        dateFieldText.delegate = self;
        dateFieldText.inputView = pick;
    }
    else if ([sender isEqual:friendsName])
    {
        NSLog(@"Pick a friend!");

        if (self.friendPickerController == nil) {
            // Create friend picker, and get data loaded into it.
            self.friendPickerController = [[PF_FBFriendPickerViewController alloc] init];
            self.friendPickerController.title = @"Select Friends";
            self.friendPickerController.delegate = self;
            self.friendPickerController.allowsMultipleSelection = NO;
        }
        [self.friendPickerController loadData];
        [self.friendPickerController clearSelection];
        [self presentModalViewController:self.friendPickerController animated:YES];

    }
    else{
        UIBarButtonItem *submitButton = [[UIBarButtonItem alloc]
                                         initWithTitle:@"Done"
                                         style:UIBarButtonItemStyleDone
                                         target:self
                                         action:@selector(submitList)]; //change this


          self.navigationItem.rightBarButtonItem = submitButton;

        }
    }

-(void)updateFriendTextField:(NSString*)subtitle
{
    friendsName.text = subtitle;
}

/*
-(void)updateSelections
{
    NSString* friendsSubtitle = @"Selected friends";
    id<PF_FBGraphUser> friend = [self.selectedFriends objectAtIndex:0];
    friendsSubtitle = friend.name;
    [self updateFriendTextField:friendsSubtitle];

    //[self handlePickerDone];
}
*/

-(void)friendPickerViewControllerDataDidChange:(PF_FBFriendPickerViewController *)friendPicker {
    NSLog(@"Current friend selections: %@", friendPicker.selection); 

}

- (void)dealloc
{
    friendPickerController.delegate = nil;
}

- (void)facebookViewControllerCancelWasPressed:(id)sender
{
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"Friend selection cancelled.");
    //[self handlePickerDone];
}

- (void)facebookViewControllerDoneWasPressed:(id)sender
{

    NSLog(@"Done was pressed.");
    //[self updateSelections];
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
4

2 回答 2

0

这个答案有多种解决方案。

就个人而言,我喜欢使用全局标头,因为从我的角度来看,它是最有效的。

我会创建一个头文件并将其命名为“global.h”

在该头文件中,我将创建以下内容:

NSString* friendsName;
NSString* wallPostText;
NSString* dateFieldText;
NSString* listFieldText;

接下来,我将在应用程序首次启动时在应用程序委托中初始化这些对象,只需调用friendsName = @"friend";

稍后,当您实际从选择中收到朋友姓名时,将该姓名保存到该全局变量中,friendsName!

请记住将#import "global.h" 导入到所有需要访问这些变量的类中!

第二种方法是在您希望访问这些变量的类中创建一个局部变量。

@property(nonatomic) NSString *friendsName;

当您推送新的 UIViewController 时,您可以在初始化后立即通过它,如下所示:

ViewControllerB *viewControllerB = [[ViewControllerB alloc] initWithNib:@"ViewControllerB" bundle:nil];
viewControllerB.friendsName = "Mark";
[self pushViewController:viewControllerB animated:YES];

希望这可以帮助!

于 2013-03-13T21:48:13.493 回答
0

您可以将它从friendPicker.selection 保存在您的委托方法之一(friendPickerViewControllerSelectionDidChangefriendPickerViewControllerDataDidChange)中。

数组中的项目是PF_FBGraphUser对象,因此您可以保存它们并使用您需要的任何内容 PF_FBGraphUser

@property (retain, nonatomic) NSString *id;
@property (retain, nonatomic) NSString *name;
@property (retain, nonatomic) NSString *first_name;
@property (retain, nonatomic) NSString *middle_name;
@property (retain, nonatomic) NSString *last_name;
@property (retain, nonatomic) NSString *link;
@property (retain, nonatomic) NSString *username;
@property (retain, nonatomic) NSString *birthday;
@property (retain, nonatomic) id<PF_FBGraphPlace> location;
于 2013-03-20T00:23:03.397 回答