Xcode 如何在UITableView中显示Twitter提要
我正试图在UITableView中显示twitter提要。我能够获得提要并记录信息。但是,我对如何显示信息而不是将其记录到控制台感到困惑。我被告知要创建一个自定义对象来存储提要中所需的数据,然后创建一个UITableVIew来显示信息,这就是我遇到的问题。有什么建议吗?有人能给我指出正确的方向吗?下面是我的代码现在的样子。我感谢您的帮助,感谢您宝贵的时间 代码如下:Xcode 如何在UITableView中显示Twitter提要,xcode,uitableview,Xcode,Uitableview,我正试图在UITableView中显示twitter提要。我能够获得提要并记录信息。但是,我对如何显示信息而不是将其记录到控制台感到困惑。我被告知要创建一个自定义对象来存储提要中所需的数据,然后创建一个UITableVIew来显示信息,这就是我遇到的问题。有什么建议吗?有人能给我指出正确的方向吗?下面是我的代码现在的样子。我感谢您的帮助,感谢您宝贵的时间 代码如下: #import "ViewController.h" #import <Accounts/Accounts.h> #i
#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
#导入“ViewController.h”
#进口”;
text=“#ikercasillasoficial Bien Iker。这是我的荣幸。奥贾拉是一位来自越南的年轻人;
截断=0;
用户={
“已启用贡献者”=0;
“创建时间”=“Wed Jan 18 02:10:12+0000 2012”;
“默认_配置文件”=1;
“默认_配置文件_图像”=0;
description=“你好,世界”;
实体={
说明={
URL=(
);
};
};
“收藏夹计数”=0;
“跟踪请求发送”=0;
“追随者数量”=2;
以下=0;
“朋友数”=18;
“已启用地理位置”=0;
id=467043064;
“id_str”=467043064;
“是否已启用翻译”=0;
“is_translator”=0;
lang=en;
“列出的计数”=0;
位置=”;
name=“Omar Devila”;
通知=0;
“轮廓\背景\颜色”=C0;
“配置文件\u背景\u图像\u url”=”http://abs.twimg.com/images/themes/theme1/bg.png";
“配置文件\u背景\u图像\u url\u https”=”https://abs.twimg.com/images/themes/theme1/bg.png";
“纵断面\背景\平铺”=0;
“配置文件\u图像\u url”=”http://pbs.twimg.com/profile_images/483760718895140864/3pLRpyzk_normal.jpeg";
“配置文件\u图像\u url\u https”=”https://pbs.twimg.com/profile_images/483760718895140864/3pLRpyzk_normal.jpeg";
“配置文件链接颜色”=0084B4;
“配置文件\侧栏\边框\颜色”=C0;
“纵断面\侧边栏\填充\颜色”=DDEEF6;
“配置文件文本颜色”=333333;
“配置文件\使用\背景\图像”=1;
受保护=0;
“屏幕名称”=设备名称;
“状态计数”=18;
“时区”=“”;
url=“”;
“utc_偏移量”=“”;
验证=0;
};
}
在类级别声明twitterFeed
数组
NumberOfSectionsTableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
行数部分
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return twitterFeed.count;
}
cellForRowAtIndexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel = twitterFeed[indexPath.row][@"user"][@"screen_name"];
return cell;
}
向我展示你记录的json或解析数据,我会帮你在TableView中显示谢谢!我真的很感激!亲爱的Meda,我在代码底部添加了它。我希望不会给你带来太多麻烦,再次感谢你!我真正需要的是用户名、日期和推文:)我找不到这些键,但请看我的考试答案请一旦我这样做(使用我自己的钥匙)我将能够将信息显示到我的tableview?此外,我必须创建一个自定义对象,其中包含要在单元格中显示的关键数据?是否正确?是,它将显示数据,是,您可以创建自定义模型类,以使代码更清晰,更清晰powerful@user3078406一杯啤酒就可以了,不,我在开玩笑,哈哈,我只是同意了哈哈!德国啤酒好吗?既然他们要拿足球世界杯了?哈哈,我会的,再一次。谢谢谢谢谢谢谢谢!!!@user3078406哈哈你们谋杀了巴西男人,为什么亚尔要这么做哈哈,好吧,祝你好运,如果你再次需要我的帮助,让我知道
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel = twitterFeed[indexPath.row][@"user"][@"screen_name"];
return cell;
}