gpt4 book ai didi

iphone - 不调用方法 didSelectRowAtIndexPath :

转载 作者:行者123 更新时间:2023-11-29 13:37:29 30 4
gpt4 key购买 nike

didSelectRowAtIndexPath:即使在将表委托(delegate)和数据源连接到文件所有者后,方法也不会调用。

当我试图打印一些东西时,它没有用这种方法打印 在下面找到我的代码供您引用:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [favorite count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell= nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"mycell"];
if (cell == nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mycell"];}

db * temp =(db *)[self.favorite objectAtIndex:indexPath.row];
cell.textLabel.text=temp.name;
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"b");

UITableViewCell *selectedCell = [secondTable cellForRowAtIndexPath:indexPath];
[secondTable.delegate tableView:secondTable didSelectRowAtIndexPath:indexPath];
cellText = selectedCell.textLabel.text;
NSLog(@"%@",cellText);
[fav addObject:cellText];
arrayTwo = tableTw.tableTwo;
msg = [NSString stringWithFormat: @" %@ ",[arrayTwo objectAtIndex:0]];
NSLog(@"%@",[arrayTwo objectAtIndex:0]);

}

-(void)checkAndCreateDatabase{
BOOL success;
NSFileManager *fileManager=[NSFileManager defaultManager];
success=[fileManager fileExistsAtPath:databasePath];
if(success)
return;

NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
}
-(IBAction)resPage:(id)sender{
NSLog(@"%@",fav);
sqlite3 *database;
favorite=[[NSMutableArray alloc]init];
if(sqlite3_open([databasePath UTF8String], &database)== SQLITE_OK){
NSString *sql=[NSString stringWithFormat:@"SELECT name,item_country.id,text.text FROM country,item_country,text WHERE country.name ='%@' AND text.item = item_country.item AND country.id = item_country.id", cellText];
const char *sqlStatement = [sql UTF8String];;
sqlite3_stmt *compiledStatement;
NSLog(@"a");
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)==SQLITE_OK){
NSLog(@"A");
while (sqlite3_step(compiledStatement)==SQLITE_ROW) {
d=[NSString stringWithCString:(char *)sqlite3_column_text(compiledStatement, 2) encoding:NSUTF8StringEncoding];
a= [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
db *info =[[db alloc]initWithText:(NSString *)d andAg:(NSString *)a];
[favorite addObject:info];
}
}
sqlite3_finalize(compiledStatement);

sqlite3_close(database);


if(favorite.count >0){
txt.text = [NSString stringWithFormat:@"%@ ", [favorite objectAtIndex:0] ];

}}
}
- (void)viewDidLoad {
{
databaseName=@"nobel10.db";
NSArray *documentPaths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentDir = [documentPaths objectAtIndex:0];
databasePath=[documentDir stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
[super viewDidLoad];
if (tableOn == nil) {
tableOn = [[table1 alloc] init];
}
if (tableTw == nil) {
tableTw = [[table2 alloc] init];
}
if (tableThre == nil) {
tableThre = [[table3 alloc] init];
}
if (tableFou == nil) {
tableFou = [[table4 alloc] init];
}

[firstTable setDataSource:tableOn];
[secondTable setDataSource:tableTw];
[thirdTable setDataSource:tableThre];
[fourthTable setDataSource:tableFou];
[fifthTable setDataSource:tableFiv];

[firstTable setDelegate:tableOn];
[secondTable setDelegate:tableTw];
[thirdTable setDelegate:tableThre];
[fourthTable setDelegate:tableFou];


tableOn.view = tableOn.tableView;
tableTw.view = tableTw.tableView;
tableThre.view = tableThre.tableView;
tableFou.view = tableFou.tableView;


{fav=[[NSMutableArray alloc]init];
cellText =[[NSString alloc]init];
secondTable=[[UITableView alloc]init];
secondTable.delegate=self;
secondTable.dataSource=self;
secondTable.tag = 20;
[self.view addSubview:secondTable];
}
}

请多多指教!

最佳答案

我认为 secondTable 不是您要处理的对象。请确定它。

关于iphone - 不调用方法 didSelectRowAtIndexPath :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10185616/

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