タイムラインを UITableView に表示したいので、次のコードを使用してツイートを取得しています。
- (void)viewDidLoad
{
[super viewDidLoad];
[self gettweets];
}
-(void)gettweets {
NSString *apiurl = [NSString stringWithFormat:@"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=idoodler"];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:apiurl]];
NSError* error;
NSDictionary * json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSArray *meta = [json valueForKeyPath:@"text"];
tweets = json;
NSLog(@"%@",meta);
}
私のログには正しいツイートが表示されています。
次に、これを使用してつぶやきを UITableView に表示します。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//return 0;
return [tweets count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdenfifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdenfifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdenfifier];
}
cell.text = [tweets objectAtIndex:indexPath.row];
[tableView reloadData];
return cell;
}
UITableView の .h ファイルに IBOutlet を作成しました。自分の間違いがどのようなものかわかりません。