0

我有一个带有标识符“tweetCell”的自定义单元格,我已将其导入到我的 tableviewcontroller.h 文件中。我已将该类链接到情节提要中的原型单元。所有的 UILabel 都连接到单元格,但我无法让 tableview 显示自定义单元格。它起作用了吗?然后一夜之间停了?!!我知道类文件需要以大写字母开头,我已经改变了这一点,但无济于事。谁能在这里发现我的错误?提前致谢......

- (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;
}
4

1 回答 1

1

这个方法是你写的- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView吗?像这样试试。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;

    }
于 2012-06-01T11:01:29.383 回答