Cocoa touch 自定义单元格未显示在tableView中
我有一个带有标识符“tweetCell”的自定义单元格,我已将其导入tableviewcontroller.h文件。我已将该类链接到故事板中的原型单元。所有UILabel都连接到单元格,但我无法让tableview显示自定义单元格。真的有用吗?然后一夜之间就停止了?!!我知道类文件需要以大写字母开头,我已经改变了这一点,但没有用。有人能在这里发现我的错误吗?提前谢谢Cocoa touch 自定义单元格未显示在tableView中,cocoa-touch,uitableview,storyboard,Cocoa Touch,Uitableview,Storyboard,我有一个带有标识符“tweetCell”的自定义单元格,我已将其导入tableviewcontroller.h文件。我已将该类链接到故事板中的原型单元。所有UILabel都连接到单元格,但我无法让tableview显示自定义单元格。真的有用吗?然后一夜之间就停止了?!!我知道类文件需要以大写字母开头,我已经改变了这一点,但没有用。有人能在这里发现我的错误吗?提前谢谢 - (void)fetchTweets { dispatch_async(dispatch_get_global_queu
- (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;
}
如果您使用的是故事板,您应该删除
If(cell==nil){…}
部分。故事板中的TableView会自动为您创建一个单元格,因此出列调用将始终返回一个单元格。如果您删除了该代码,并且出现异常,您将知道您的单元格标识符不匹配。这不是必需的。这是一种可选方法。如果它不存在,tableView将使用1节作为默认值。嗨,matthias,我已经更改了if(cell==nil){…}部分,但不幸的是,它仍然不能工作。我不知道它是否说明了情况,但行CustomCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];获取绿色消息“线程1:信号SIGABRT”