Ios 将Facebook好友名称传递到文本字段时出现问题

Ios 将Facebook好友名称传递到文本字段时出现问题,ios,objective-c,facebook,facebook-graph-api,Ios,Objective C,Facebook,Facebook Graph Api,我正在选择一个facebook好友。我想在启动facebook好友选取器的文本字段中显示facebook好友的姓名 谢谢 另外,抓取用户字符串名称和选择要向其发送对象的朋友之间是否有区别?因为这就是用户将要做的。因此,我需要显示用户名的字符串值,但我还必须将一个对象与该用户关联 -(IBAction)cancelList; -(IBAction)submitList; -(IBAction)datePicker; @property (strong, nonatomic) IBOutlet U

我正在选择一个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];
}
-(void)textfielddbeginediting:(UITextField*)发送方
{
sender.delegate=self;
如果([sender isEqual:dateFieldText])
{
UIBarButtonItem*doneButton=[[UIBarButtonItem alloc]
initWithTitle:@“保存日期”
风格:uibarbuttonimstyledone
目标:自我
操作:@选择器(日期选择器)];
self.navigationItem.RightBarButtonim=doneButton;
pick=[[UIDatePicker alloc]init];
[拾取设置帧:CGRectMake(0200320120)];
//[pick addTarget:self action:@selector(done)for ControlEvents:UIControlEventValueChanged];
dateFieldText.delegate=self;
dateFieldText.inputView=拾取;
}
else if([发件人isEqual:friendsName])
{
NSLog(@“选择一个朋友!”);
if(self.friendPickerController==nil){
//创建好友选择器,并将数据加载到其中。
self.friendPickerController=[[pffbfriendpickerservicewcontrolleralloc]init];
self.friendPickerController.title=@“选择朋友”;
self.friendPickerController.delegate=self;
self.friendPickerController.allowsMultipleSelection=否;
}
[self.FrienderPickerController loadData];
[self.FrienderPickerController清除选择];
[self-presentModalViewController:self.FriendsPickerController动画:是];
}
否则{
UIBarButtonItem*submitButton=[[UIBarButtonItem alloc]
initWithTitle:@“完成”
风格:uibarbuttonimstyledone
目标:自我
操作:@selector(submitList);//更改此选项
self.navigationItem.rightBarButtonItem=提交按钮;
}
}
-(void)updateFriendTextField:(NSString*)副标题
{
friendsName.text=副标题;
}
/*
-(无效)更新选择
{
NSString*Friendsubtitle=@“选定的朋友”;
id friend=[self.selectedFriends对象索引:0];
Friendsubtitle=friend.name;
[self-updateFriendTextField:friendsSubtitle];
//[自行处理];
}
*/
-(void)FriendPickerViewController数据更改:(PF_fFriendPickerViewController*)friendPicker{
NSLog(@“当前好友选择:%@”,friendPicker.selection);
}
-(无效)解除锁定
{
friendPickerController.delegate=nil;
}
-(无效)facebookViewControllerCancelWasPressed:(id)发件人
{
[self.presentingViewController dismissViewControllerAnimated:YES完成:nil];
NSLog(@“朋友选择已取消”);
//[自行处理];
}
-(无效)已按下FaceBookViewControllerDone:(id)发件人
{
NSLog(@“已按完成”);
//[自我更新选择];
[self.presentingViewController dismissViewControllerAnimated:YES完成:nil];
}

这个答案有多种解决方案

就个人而言,我喜欢使用全局标题,因为从我的观点来看,它是最有效的

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

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

NSString*friendsName
NSString*wallPostText
NSString*日期字段文本
NSString*listFieldText

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

稍后,当您从所选内容中实际收到好友名称时,请将该名称保存到该全局变量friendsName

记住#将“global.h”导入所有需要访问这些变量的类中

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

@property(非原子)NSString*friendsName

在推送新UIViewController时,可以在初始化后立即将其传递,如下所示:


ViewControllerB*ViewControllerB=[[ViewControllerB alloc]initWithNib:@“ViewControllerB”bundle:nil]
viewControllerB.friendsName=“标记”
[自推ViewController:viewControllerB动画:是]


希望这有帮助

您可以将它从friendPicker.selection中保存到您的一个委托方法(
FriendPickerViewController SelectionDidChange
FriendPickerViewController DataDidChange

数组中的项目是
PF\u FBGraphUser
对象,因此您可以保存它们并使用
PF\u 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;
@property(保留,非原子)NSString*id;
@属性(保留,非原子)NSString*名称;
@属性(保留,非原子)NSString*第一个\u名称;
@属性(保留,非原子)NSString*中间名称;
@属性(保留,非原子)NSString*姓氏;
@属性(保留,非原子)NSString*链接;
@属性(保留,非原子)NSString*用户名;
@属性(保留,非原子)NSString*生日;
@属性(保留,非原子)id位置;

你能简化你的问题吗?我不清楚你的要求是什么。基本上我可以启动facebook好友选取器,选择好友,但我不知道如何将数据[如用户名等]传递到另一个视图中。好友选取器以表格视图的方式呈现。不要将标记用于与IDE无关的问题。是否使用解析?PF_fFriendPickServiceController类在哪里