gpt4 book ai didi

ios - cellForRowAtIndexPath 没有被调用?

转载 作者:行者123 更新时间:2023-11-29 03:27:42 27 4
gpt4 key购买 nike

我的 cellForRowAtIndexPath 并非每次都会触发我将 dataSourcedelegate 设置给文件所有者。我还设置了引用 socket 。我还尝试了 tbl.delegate=self;tbl.datasource=self; 但它不起作用。

我能做什么?

   -(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];
}

//这段代码是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;
}

请解决我的问题。你没有得到任何东西,请告诉我。

最佳答案

您需要设置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;
}

关于ios - cellForRowAtIndexPath 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20245711/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com