标签文本是 'nil',尽管分配了一些文本
Label text is 'nil', inspite of assigning some text
我正在开发一个应用程序。我有一个桌面视图。我为 TableView Cell 设置了一个单独的 class,名为“cellTable”。我通过导入单元格的 .h 文件在另一个名为“resultViewController”中使用此 class。我宣布,
cellTable *cellElement;
在 'resultViewControler.h' 中。我尝试使用
更改'resultViewController'中'cellTable'中声明的标签
cellElement.resultname.text = testNamesA[indexPath.row];
尽管 'testNamesA[,我得到 'nil' for 'cellElement.resultname.text' indexPath.row]' 有一定的价值。屏幕截图显示了有关问题的确切图片,
请帮我解决这个问题...
您正在 cellForRowAtIndexPath 方法中设置单元格的属性,因此不在
中
cellElement.resultname.text = testNamesA[indexPath.row];
是
cell.resultname.text = testNamesA[indexPath.row];
例如
#import "yourTableViewCell.h"
现在将 tableView:cellForRowAtIndexPath 更改为
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
yourTableViewCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.resultname.text = testNamesA[indexPath.row];
return cell;
}
举个例子,你可以去here。
根据你的问题,我的理解是你创建了单独的 UItableViewCell 并且你在 ViewController.But 中导入了那个单元格你不知道如何调用和使用那个自定义单元格在 table 查看委托方法中。
我告诉你now.Once你导入自定义单元格你需要在 cellForRowAtIndexPath 方法中调用下面的代码行。
如果你用xib创建cellTable
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cellTable *cellElement = (cellTable *)[tableView dequeueReusableCellWithIdentifier:@"cell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"cellTable" owner:self options:nil];
if(cellElement == nil){
cellElement = nib[0];
}
cellElement.resultname.text = testNamesA[indexPath.row];
return cellElement;
}
我正在开发一个应用程序。我有一个桌面视图。我为 TableView Cell 设置了一个单独的 class,名为“cellTable”。我通过导入单元格的 .h 文件在另一个名为“resultViewController”中使用此 class。我宣布,
cellTable *cellElement;
在 'resultViewControler.h' 中。我尝试使用
更改'resultViewController'中'cellTable'中声明的标签cellElement.resultname.text = testNamesA[indexPath.row];
尽管 'testNamesA[,我得到 'nil' for 'cellElement.resultname.text' indexPath.row]' 有一定的价值。屏幕截图显示了有关问题的确切图片,
请帮我解决这个问题...
您正在 cellForRowAtIndexPath 方法中设置单元格的属性,因此不在
中 cellElement.resultname.text = testNamesA[indexPath.row];
是
cell.resultname.text = testNamesA[indexPath.row];
例如
#import "yourTableViewCell.h"
现在将 tableView:cellForRowAtIndexPath 更改为
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
yourTableViewCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.resultname.text = testNamesA[indexPath.row];
return cell;
}
举个例子,你可以去here。
根据你的问题,我的理解是你创建了单独的 UItableViewCell 并且你在 ViewController.But 中导入了那个单元格你不知道如何调用和使用那个自定义单元格在 table 查看委托方法中。
我告诉你now.Once你导入自定义单元格你需要在 cellForRowAtIndexPath 方法中调用下面的代码行。
如果你用xib创建cellTable
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cellTable *cellElement = (cellTable *)[tableView dequeueReusableCellWithIdentifier:@"cell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"cellTable" owner:self options:nil];
if(cellElement == nil){
cellElement = nib[0];
}
cellElement.resultname.text = testNamesA[indexPath.row];
return cellElement;
}