Я пытаюсь сделать программу викторины. Когда пользователь нажимает правильный ответ, программа работает правильно, но если пользователь нажимает неправильный ответ, программа должна показывать правильный ответ, программа знает, какая ячейка верна, но не может вызвать метод.Установить целочисленное значение в indexpath.row
Это моя часть проекта;
-(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];
Благодарим вас за интерес.
Это не сразу понятно, что ваш вопрос. Постарайтесь уточнить, где вам нужна помощь. – Snowman
Например, в моем вопросе у меня есть 4 ответа, когда пользователь нажимает неправильный ответ, я хочу показать правильный ответ пользователю, поэтому мне хочется, чтобы мигать правильная ячейка ответа, но, как вы можете видеть выше, метод не вызывает , Извините, у меня нет хорошего английского, надеюсь, вы поймете, что я хочу делать. –