【发布时间】:2017-06-21 13:10:10
【问题描述】:
在 StoryBoard 中,我有一个场景包含一些 TextField、按钮和 UITableView。在头文件中声明了 UITableView 的一个实例,但是当我尝试访问方法“cellForRowAtIndexPath”时,我收到以下错误
this class is not key value coding-compliant for the key tableView.
我用谷歌搜索了那个错误,一些结果表明它是关于将 DataSource 和 Delegate 属性链接到 ViewController,但我仍然收到同样的错误
请告诉我如何解决此错误。
code-1:
-(UITableViewCell *) tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForRowAtIndexPath");
NSString *cellIdentifier = @"cellId";
UITableViewCell *cell = [tableView1
dequeueReusableCellWithIdentifier:cellIdentifier
forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
//[cell.textLabel setText: [dataArray
objectAtIndex:indexPath.row]];
if (textFieldRowNameAsString != nil)
cell.textLabel.text = textFieldRowNameAsString;
return cell;
}
代码 2:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate,
UITableViewDataSource>
{
NSString *textFieldRowNameAsString;
UITableView *tableView1;
UITableViewCell *prototypeCell;
UIView *contentView;
}
image-1:
【问题讨论】:
-
您想要“访问方法'cellForRowAtIndexPath'”的原因是什么?这不是你通常需要做的。
标签: ios objective-c uitableview