我想顯示twitter飼料到UITableView。我能夠得到飼料和NSLog的信息。但是,我很困惑如何顯示信息而不是將其記錄到控制檯。我被告知要創建一個自定義對象,以便從Feed中存儲所需的數據,然後創建一個UITableVIew來顯示信息,那就是我卡住的地方。有沒有任何建議,或有人能指出我的方向正確嗎?這是我的代碼現在的樣子。我感謝您的寶貴時間,並感謝您的幫助。如何顯示Twitter的飼料到UITableView
CODE BELOW:
#import "ViewController.h"
#import <Accounts/Accounts.h>
#import <Social/Social.h>
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[self refreshTwitter];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)refreshTwitter
{
ACAccountStore *accountStore = [[ACAccountStore alloc]init];
if (accountStore != nil)
{
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
if (accountType != nil)
{
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
//Succesful Access
NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType];
if (twitterAccounts != nil)
{
ACAccount *currentAccount = [twitterAccounts objectAtIndex:0];
if (currentAccount != nil)
{
NSString *requestString = @"https://api.twitter.com/1.1/statuses/user_timeline.json";
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:requestString] parameters:nil];
[request setAccount:currentAccount];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ((error == nil) && ([urlResponse statusCode] == 200))
{
NSArray *twitterFeed = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSDictionary *firstPost = [twitterFeed objectAtIndex:0];
NSLog(@"firstPost = %@", [firstPost description]);
}
}];
}
}
}
else
{
//Access Denied
}
}];
}
}
}
@end
JSON DATA:
2014-07-08 13:22:37.442 demoApp[19277:4607] firstPost = {
contributors = "<null>";
coordinates = "<null>";
"created_at" = "Wed Jul 02 18:29:43 +0000 2014";
entities = {
hashtags = (
{
indices = (
0,
20
);
text = ikercasillasoficial;
}
);
symbols = (
);
urls = (
);
"user_mentions" = (
);
};
"favorite_count" = 0;
favorited = 0;
geo = "<null>";
id = 484403559677837312;
"id_str" = 484403559677837312;
"in_reply_to_screen_name" = "<null>";
"in_reply_to_status_id" = "<null>";
"in_reply_to_status_id_str" = "<null>";
"in_reply_to_user_id" = "<null>";
"in_reply_to_user_id_str" = "<null>";
lang = es;
place = "<null>";
"retweet_count" = 0;
retweeted = 0;
source = "<a href=\"http://twitter.com/#!/download/ipad\" rel=\"nofollow\">Twitter for iPad</a>";
text = "#ikercasillasoficial Bien Iker. Pero fuiste muy sutil. Ojala ese hp cuando tenga hijos se le pudran en el vientre se su mujer.";
truncated = 0;
user = {
"contributors_enabled" = 0;
"created_at" = "Wed Jan 18 02:10:12 +0000 2012";
"default_profile" = 1;
"default_profile_image" = 0;
description = "Hello world";
entities = {
description = {
urls = (
);
};
};
"favourites_count" = 0;
"follow_request_sent" = 0;
"followers_count" = 2;
following = 0;
"friends_count" = 18;
"geo_enabled" = 0;
id = 467043064;
"id_str" = 467043064;
"is_translation_enabled" = 0;
"is_translator" = 0;
lang = en;
"listed_count" = 0;
location = "";
name = "Omar Devila";
notifications = 0;
"profile_background_color" = C0DEED;
"profile_background_image_url" = "http://abs.twimg.com/images/themes/theme1/bg.png";
"profile_background_image_url_https" = "https://abs.twimg.com/images/themes/theme1/bg.png";
"profile_background_tile" = 0;
"profile_image_url" = "http://pbs.twimg.com/profile_images/483760718895140864/3pLRpyzk_normal.jpeg";
"profile_image_url_https" = "https://pbs.twimg.com/profile_images/483760718895140864/3pLRpyzk_normal.jpeg";
"profile_link_color" = 0084B4;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = 1;
protected = 0;
"screen_name" = DevilaOmar;
"statuses_count" = 18;
"time_zone" = "<null>";
url = "<null>";
"utc_offset" = "<null>";
verified = 0;
};
}
顯示我的JSON或登錄解析數據,我會幫助你在實現代碼如下 – meda
謝謝顯示它!對此,我真的非常感激! – user3078406
親愛的Meda,我在代碼的底部添加了它。我希望不要再給你帶來太多麻煩,謝謝! – user3078406