我有一个带有识别器"tweetCell"的自定义单元格,我已将其导入到我的tableviewcontroller.h文件中。我已将类链接到故事板中的原型单元格。所有 UILabel 都连接到单元格,但我无法让表视图显示自定义单元格。它确实有效吗?然后一夜之间就停了下来?!!我知道类文件需要以大写字母开头,我已经更改了它,但无济于事。任何人都可以在这里发现我的错误吗?提前感谢...
- (void)fetchTweets
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* data = [NSData dataWithContentsOfURL:
[NSURL URLWithString: @"http://search.twitter.com/search.json?q=%23mysearchhashtag"]];
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";
customCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
NSString *tweetText = [tweet valueForKey:@"text"];
NSArray *tweetComponents = [tweetText componentsSeparatedByString:@":"];
cell.firstDetail.text = [tweetComponents objectAtIndex:0];
cell.secondDetail.text = [tweetComponents objectAtIndex:1];
cell.thirdDetail.text = [tweetComponents objectAtIndex:2];
return cell;
}
你- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
写了这个方法吗?尝试这样。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}