已经有两个星期了,我无法找到有用的答案,我已经尝试了很多代码,没有任何对我有用的工作,实际上我正在尝试构建一个登录页面能够用户从他们的Facebook或Twitter登录/登录,它完全适用于Facebook,但推特上的问题。
我已经尝试过以下代码,请提供建议和帮助,因为我仍然收到错误并且错误是
(属性twitterHandle未在#34类型的对象上找到; ViewController")
这是我使用的代码。请注意我使用 Parse 作为我的数据库。
*我已经在名为Twitter的标题中创建了一个操作按钮
-(IBAction)Twitter:(id)sender;
*我在m文件中有这个代码,如下所示:
- (IBAction)Twitter:(id)sender {
{
// borrowed from: http://eflorenzano.com/blog/2012/04/18/using-twitter-ios5-integration-single-sign-on/
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[store requestAccessToAccountsWithType:twitterType options:nil completion:^(BOOL granted, NSError *error)
{
if(granted) {
// Access has been granted, now we can access the accounts
// Remember that twitterType was instantiated above
NSArray *twitterAccounts = [store accountsWithAccountType:twitterType];
// If there are no accounts, we need to pop up an alert
if(twitterAccounts != nil && [twitterAccounts count] == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Twitter Accounts"
message:@"There are no Twitter accounts configured. You must add or create a Twitter separately."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
} else {
ACAccount *account = [twitterAccounts objectAtIndex:0];
// Do something with their Twitter account
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/account/verify_credentials.json"];
SLRequest *req = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:nil];
// Important: attach the user's Twitter ACAccount object to the request
req.account = account;
[req performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse,
NSError *error)
{
// If there was an error making the request, display a message to the user
if(error != nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Twitter Error"
message:@"There was an error talking to Twitter. Please try again later."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
// Parse the JSON response
NSError *jsonError = nil;
id resp = [NSJSONSerialization JSONObjectWithData:responseData
options:0
error:&jsonError];
// If there was an error decoding the JSON, display a message to the user
if(jsonError != nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Twitter Error"
message:@"Twitter is not acting properly right now. Please try again later."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
NSString *screenName = [resp objectForKey:@"screen_name"];
self.twitterHandle = screenName;
PFUser *currentUser = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"username" equalTo:currentUser.username];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// Do something with the found objects
for (PFObject *object in objects)
{
object[@"TwitterHandle"] = self.twitterHandle;
[object saveInBackground];
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}];
}
}
}];
}
}
请请帮助:(
答案 0 :(得分:1)
(property twitterHandle not found on object of type "ViewController")
告诉你,在某个地方,你试图在twitterHandle
类型的对象上访问一个名为ViewController
的属性,该对象没有这样的属性。
我怀疑问题出在这一行:
self.twitterHandle = screenName;
您只需要在视图控制器界面中添加一个属性,如下所示:
@property (nonatomic, strong) NSString *twitterHandle;