gpt4 book ai didi

ios - 为 indexpath.row 设置一个整数值

转载 作者:行者123 更新时间:2023-11-28 20:10:25 24 4
gpt4 key购买 nike

我正在尝试制作测验程序。当用户点击正确答案时,程序正常工作,但如果用户点击错误答案,程序必须显示正确答案,程序知道哪个单元格是正确的,但它不能调用该方法。

这是我项目的部分;

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

CGRect rect = cell.frame;
UIView * view = [[UIView alloc] init];
UIImageView *back = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ListGray"] ];

databaseNameUser = SQL;
NSArray *documentPathsUser = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirUser = [documentPathsUser objectAtIndex:0];
databasePathUser = [documentsDirUser stringByAppendingPathComponent:databaseNameUser];
sqlLocal= [[Sqlite alloc]initWithFile:databasePathUser];


NSString *query1 = [NSString stringWithFormat: @"SELECT AnswerID from tblAnswer where QuestionID = %i",[[questionsID objectAtIndex:i] intValue]];
answerInfo=[sqlLocal executeQuery:query1];
NSMutableArray *answerIDArray = [[NSMutableArray alloc]init];

for (NSMutableDictionary *d in answerInfo) {

[answerIDArray addObject:[d valueForKey:@"AnswerID"]];

}


NSString *query2 = [NSString stringWithFormat: @"SELECT answerID from tblDogruCevaplar where QuestionID = %i",[[questionsID objectAtIndex:i] intValue]];
NSArray *answerInfo2=[sqlLocal executeQuery:query2];
//NSMutableArray *answerDogru = [[NSMutableArray alloc]init];

for (NSMutableDictionary *d in answerInfo2) {

answerDogruDefault=[d valueForKey:@"answerID"];

}


for (int indexOfArray = 0; indexOfArray<4; indexOfArray++ ){



if ([answerDogruDefault intValue] == [[answerIDArray objectAtIndex:indexOfArray] intValue]){

//NSLog(@"indexpath = %i",indexOfArray);

indexPathInt = indexOfArray;

}
}



BOOL selx;
if (answerType==2)
selx = [self isSelected:indexPath];
else
selx = [lastIndexPath isEqual:indexPath];

if (selx) {
back = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SecildiYesilTikli2.png"] ];
cell.textLabel.textColor = [UIColor whiteColor];
[view addSubview:back];
cell.backgroundView = view;


if ([self isAnswerCorrect]) {

if (indexPathInt == indexPath.row) {

[NSTimer scheduledTimerWithTimeInterval:3.f target:self selector:@selector(dogruCevapSignal:) userInfo:cell repeats:NO];
}

}else{

cell.textLabel.textColor = [UIColor redColor];

NSIndexPath *a = [NSIndexPath indexPathForRow:indexPathInt inSection:0];

NSLog(@"a = %i",a.row);

cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPathInt inSection:0]];

[NSTimer scheduledTimerWithTimeInterval:3.f target:self selector:@selector(dogruCevapSignal:) userInfo:cell repeats:NO];

}

back.frame = CGRectMake(0, 12,rect.size.width,rect.size.height-12);
} else {
cell.accessoryView = nil;
if (lastIndexPath != nil){
cell.textLabel.textColor = [UIColor blackColor];
[view addSubview:back];
cell.backgroundView = view;

back.frame = CGRectMake(0, 12,rect.size.width,rect.size.height-12);
back = nil;
}
}
[view addSubview:back];
cell.backgroundView = view;

back.frame = CGRectMake(0, 12,rect.size.width,rect.size.height-12);

}

-(void)dogruCevapSignal:(NSTimer *)cell{

UITableViewCell *defaultCell=(UITableViewCell *)[cell userInfo];

[UIView animateWithDuration:0.1f delay:0 options:(UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat) animations:^{
[UIView setAnimationRepeatCount:3];
defaultCell.alpha = 0;
} completion: ^(BOOL finished) {
defaultCell.hidden = YES;

[UIView animateWithDuration:0.1 animations:^{
defaultCell.alpha = 1;
} completion: ^(BOOL finished) {
defaultCell.hidden = NO;
defaultCell.textLabel.textColor = [UIColor blueColor];
}];

}];
}

我不能在错误的答案中调用这个方法。

[NSTimer scheduledTimerWithTimeInterval:3.f target:self selector:@selector(dogruCevapSignal:) userInfo:cell repeats:NO];

感谢您的关注。

最佳答案

NSIndexPath.row 是只读的,因此您需要从现有对象创建一个新的 NSIndexPath 对象,如下所示:

NSIndexPath *original = ...
int newRow = ...;
NSIndexPath *changedRow = [NSIndexPath
indexPathForRow:newRow // Use the new row
inSection:original.section]; // Use the original section

关于ios - 为 indexpath.row 设置一个整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20524943/

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