2014-03-25 78 views
0

我想表明我的表视图定制的电池。我正确地做了这些步骤表视图没有显示我的自定义单元格

  • 添加一个表视图到故事板。
  • 设计使所述细胞与两个按钮,一个图像视图,和三个标签。
  • 在.h文件中为我的标签,图像视图设置iboutlets,为它的单元格和子类添加一个类。使用uitableviewcell
在我的表视图控制器类

我做这些事情

  • 从Web服务中获得的一些值,并将其加载到数组中的viewDidLoad中。
  • 中的cellForRowAtIndexPath我已创建的单元格,只加载一些值,我需要在细胞中显示。为了测试,我只是给标签提供一个示例文本。

但是当我运行该应用所设计的细胞不显示。只有空行在那里。

什么是错了,我没有...我无法理解......请帮助我的人..

下面

是我的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"cell"; 
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
duplicateCell *cell = (duplicateCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
cell.delegate_D = self; 
// TacleCell *cell = (TacleCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
//cell.delegate = self; 
// Configure the cell... 

NSArray* currentDuplicates = [self.duplicateArray objectAtIndex:indexPath.row]; 
NSLog(@"DUPLICATE IN DUPLICATE:%@",currentDuplicates); 

cell.Name_D.text = @"test name"; 


return cell; 
} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
//#warning Potentially incomplete method implementation. 
// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
//#warning Incomplete method implementation. 
// Return the number of rows in the section. 
NSLog(@"COUNT:%[email protected]",[self.duplicateArray count]); 

return [self.duplicateArray count]; 
} 


- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

// Uncomment the following line to preserve selection between presentations. 
// self.clearsSelectionOnViewWillAppear = NO; 

// Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
//self.navigationItem.rightBarButtonItem = self.editButtonItem; 
[self.tableView registerClass:[duplicateCell class] forCellReuseIdentifier:@"cell"]; 
self.title = @"Duplicate Req"; 
self.duplicateArray = [TableViewController getDuplicateList]; 
NSLog(@"DUPZ %@",self.duplicateArray); 

} 

请帮助我的人......

编辑:下面的图像将帮助你了解我的情况,我认为..

second view is the one i got trouble

i gave cell Identifier like this

这里是我的故事Bord ..你可以看到最后一个视图控制器(在右上角)是我谈论的一个。它旁边还有一个功能相同的功能,但它的功能就像是一种魅力。我使用了相同的代码,并遵循相同的步骤。为什么这不显示我正确的结果..?

story board

我已经解决了ISSUE..I都给予了WRONG SEGUE。我所做的就是,我之间创造了两条表意见SEGUE并执行SEGUE IN MY ALERT VIEW..NOW正常工作......

谢谢大家WHO指导我..

+1

从viewDidLoad中取出的registerClass并再次检查** ** Name_D连接到类文件 –

+1

一直在cellIdentifier被提供给故事板的电池? – AppleDelegate

+0

是的,我没有包括它..但是当我运行该应用程序时,它给了我cellforRowAtindexpath方法中第二行的错误。这就是为什么我包括该行。如果我删除它,它给了我这个错误终止应用程序由于未捕获的异常'NSInternalInconsistencyException',原因:'无法使标识符单元出列单元格 - 必须注册一个标记的nib或类或连接故事板中的原型单元格' – Darshana

回答

0

ü需要初始化当它没有被deque收到时,这个单元格会被删除

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"cell"; 
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
duplicateCell *cell = (duplicateCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
if(cell == nil) 
{ 
cell = [[duplicateCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
+0

我应用代码..但没有发生:( – Darshana

0

嗨使用xib定制UITableViewCell类并在xib中绘制单元格。

然后使用这个代码在你的tableView类

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"cell"; 

    duplicateCell *cell = (duplicateCell *)[tableView dequeueReusableCellWithIdentifier: cellIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"duplicateCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    cell.nameLabel.text = [tableData objectAtIndex:indexPath.row]; 
    cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]]; 
    cell.prepTimeLabel.text = [prepTime objectAtIndex:indexPath.row]; 

    return cell; 
} 
相关问题