[英]cellForRowAtIndexPath is not called?
My cellForRowAtIndexPath
does not fire everytime I set dataSource
and delegate
to the file owner. 每次设置
dataSource
并将其delegate
给文件所有者时,我的cellForRowAtIndexPath
不会触发。 I also set referencing outlet. 我还设置了引用出口。 I also try
tbl.delegate=self;
我也尝试
tbl.delegate=self;
and tbl.datasource=self;
和
tbl.datasource=self;
but it does not work. 但它不起作用。
What can I do? 我能做什么?
-(void)load
{
[name resignFirstResponder];
[salary resignFirstResponder];
name.text=@"";
salary.text=@"";
[tblViewController.data removeAllObjects];
NSString *insertStatement = [NSString stringWithFormat:@"select * from emp"];
sqlite3_stmt *statement;
NSString *path= [self getDBPath];
if (sqlite3_open([path UTF8String], &db) == SQLITE_OK)
{
if (sqlite3_prepare_v2(db, [insertStatement UTF8String], -1,&statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
NSMutableDictionary *record=[[NSMutableDictionary alloc]init];
NSString *nm= [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,0)];
NSString * sl= [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,1)];
[record setValue:nm forKey:@"name"];
[record setValue:sl forKey:@"salary"];
NSLog(@"%@ %@",nm,sl);
[tblViewController.data addObject:record];
NSLog(@"%@",tblViewController.data);
}
sqlite3_finalize(statement);
}
sqlite3_close(db);
}
NSLog(@"%lu",(unsigned long)[tblViewController.data count]);
[tblViewController.tbl reloadData];
}
//This code is of tableviewcontroller.m //此代码是tableviewcontroller.m的
#import "tableViewController.h"
#import "ViewController.h"
@interface tableViewController ()
@end
@implementation tableViewController
@synthesize tbl,data;
@synthesize viewOfTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"only for check");
[self setup];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//[self setup];
tbl.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-( NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-( NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[[data objectAtIndex:indexPath.row] valueForKey:@
"name"];
cell.detailTextLabel.text=[[data objectAtIndex:indexPath.row]
valueForKey:@"salary"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//name.text =[[data objectAtIndex:indexPath.row] valueForKey:@"name"];
// salary.text=[[data objectAtIndex:indexPath.row] valueForKey:@"salary"];
}
- (void)setup
{
//Store the whole view in uiView...mac
// [[NSBundle mainBundle] loadNibNamed:@"RegistrationViewController" owner:self options:nil];
viewOfTable=[[UIView alloc]initWithFrame:self.view.frame];
[viewOfTable addSubview:self.view];
self.viewOfTable.translatesAutoresizingMaskIntoConstraints=YES;
}
Please solve my problem. 请解决我的问题。 You didn't get anything then please tell me.
您什么都没得到,请告诉我。
You need to set Table DataSource in order to tableView to construct table rows. 您需要设置Table DataSource以便tableView构造表行。
#import "tableViewController.h"
#import "ViewController.h"
@interface tableViewController () <UITableViewDataSource,UITableViewDelegate>
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
tbl.dataSource = self
tbl.delegate = self;
}
或者您可以检查数据数组中是否存在错误,因为如果其大小为0,则说明某节中没有行,并且这些行中也没有单元格,并且永远不会调用cellForRowAtIndexPath ...
You should set dataSource and delegate. 您应该设置数据源和委托。 When you do this, check tbl.
执行此操作时,请检查tbl。 Maybe it nil?
也许没有? If not check what value returns
如果没有检查返回什么值
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
If you implement 如果实施
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
check it. 核实。
No more options. 没有更多选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.