好吧,这是我过去几天一直在挠头的东西。我为我的表格视图创建了一个自定义单元格。我为这个单元格创建了一个单独的类(customCell.h),并在Xcode中将它们连接在一起。 自定义单元格有四个UI标签,我已在自定义单元格的.h文件中声明并通过情节提要链接到自定义单元格。将twitter搜索链接到自定义tableview单元格
我已导入customCell.h头文件到我的表视图控制器
我试图做在Twitter上搜索,然后填充表视图和自定义单元格与细节的.h文件各种推文。问题是我不知道如何将推特的结果链接到我的自定义单元格中的4个UI标签插座。
当我在我的表视图实现文件中声明自定义单元格的某些插口(即使我已导入自定义单元格的.h文件)xcode说它不识别名称
我已经复制下面详细的编码,只要我可以得到。任何帮助将非常感激。在此先感谢
- (void)fetchTweets
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* data = [NSData dataWithContentsOfURL:
[NSURL URLWithString: @"THIS IS WHERE MY TWITTER SEARCH STRING WILL GO.json"]];
NSError* error;
tweets = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
});
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return tweets.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TweetCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
NSString *text = [tweet objectForKey:@"text"];
NSString *name = [[tweet objectForKey:@"user"] objectForKey:@"name"];
NSArray *arrayForCustomcell = [tweet componentsSeparatedByString:@":"];
cell.textLabel.text = text;
cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name];
return cell;
}
太棒了 - 感谢Steffen – Alan