在这个屏幕截图显示的标签,你可以看到,我已经加入的UITableView的UIViewController中然后在它添加一些标签定制的UITableViewCell。但问题是当我运行应用程序。所有的单元格都是空的。根本没有标签。
我没有得到什么可以是问题。我搜索了网页并阅读了教程,但无法解决它。
在这个屏幕截图显示的标签,你可以看到,我已经加入的UITableView的UIViewController中然后在它添加一些标签定制的UITableViewCell。但问题是当我运行应用程序。所有的单元格都是空的。根本没有标签。
我没有得到什么可以是问题。我搜索了网页并阅读了教程,但无法解决它。
我经过一番努力就自己解决了这个问题。
其实当你创建一个自定义单元格,你必须做这些事情:
现在在要实现UITableView的类中导入CustomCell类,并使用您在CustomCell类中定义的属性。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyCustomCell";
CustomCell*cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
}
// Here we use the provided setImageWithURL: method to load the web image
// Ensure you use a placeholder image otherwise cells will be initialized with no image
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
cell.myCustomLabel.text = @"My Text";
return cell;
}
我做这一切,我的问题就解决了请不要忘记连接代表&数据源和表。
希望这会帮助他人。
不应该[UITableViewCell alloc]实际上是[CustomCell alloc] –
重要的部分是单元标识符。确保它在故事板和tableView:cellForRowAtIndexPath方法中都是相同的。 –
在tableview的委托方法中,cellforrowatindexpath里面有一个uitableviewcell,在这个单元格的初始化中应该有一个标识符。可能是“cell”或“cellIdentifier”。
您只需从故事板中选择您的单元格,然后将此标识符字符串输入故事板,其中uitableviewcell的属性检查器保留在其中。
希望这有助于.. :)
这是有点晚了,但你可以从你的故事板设置您的视图清晰颜色的背景色解决您的问题。
在故事板@“细胞”
第一组小区标识符然后设置标签的标签
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
UILabel *lblDate = (UILabel*)[cell viewWithTag:101];
UILabel *lblDistance = (UILabel*)[cell viewWithTag:102];
UILabel *lbltype = (UILabel*)[cell viewWithTag:103];
lblDate.text = [temp objectAtIndex:indexPath.row] valueForKey:@"date"] stringByReplacingOccurrencesOfString:@"-" withString:@"/"]];
lblDistance.text = [NSString stringWithFormat:@"%@ KM",[[temp objectAtIndex:indexPath.row] valueForKey:@"distance"]];
NSString *type = [NSString stringWithFormat:@"%@",[[temp objectAtIndex:indexPath.row] valueForKey:@"distance"]];
if([type isEqualToString:@"0"])
{
lbltype.text = @"Personal";
}
else
{
lbltype.text = @"Bussiness";
}
// Configure
return cell;
}
你是如何加入细胞表视图?你可以粘贴你的表格视图委托方法。 –