[英]didSelectRowAtIndexPath not being called?
由於某些奇怪的原因,我的代碼中沒有調用我的didSelectRowAtIndexPath
。 有人知道為什么嗎? 其他所有工作都可以,這可能與我的部分有關。 我不明白為什么我的刪除類有效,但didSelectRowAtIndexPath
無效。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.subjectArray.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [self.subjectArray objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[self.sectionArrays objectAtIndex:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableViewer cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *currentSectionArray = [self.sectionArrays objectAtIndex:indexPath.section];
//populates the table based on which view is selected.
UITableViewCell *cell = [tableViewer dequeueReusableCellWithIdentifier:@"todayCell"];
NSString *toDoItem = [currentSectionArray objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem;
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.minimumScaleFactor = 0.5;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableViews commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSMutableArray *currentSectionArray = [self.sectionArrays objectAtIndex:indexPath.section];
NSString *currentStringSubject = [self.subjectArray objectAtIndex:indexPath.section];
NSMutableDictionary *tempDic = [self.mainDictionary objectForKey:currentStringSubject];
NSArray *temp = [tempDic allKeysForObject:[currentSectionArray objectAtIndex:indexPath.row]];
NSString *key = [temp lastObject];
int keyInt = [key integerValue];
int maxKey = [[[tempDic allKeys]lastObject]integerValue];
NSLog(@"KEYINT%d",keyInt);
[tempDic removeObjectForKey:key];
if (keyInt != maxKey) {
for (int x = keyInt; x != -99; x++) {
int xIncrease = x + 1;
NSLog(@"%@",[NSString stringWithFormat:@"xIncrease%d",xIncrease]);
NSString *tempWHAT = [tempDic objectForKey:[NSString stringWithFormat:@"%d",xIncrease]];
NSLog(@"tempDic%@",tempDic);
NSLog(@"tempWhat%@",tempWHAT);
if ([tempWHAT length] == 0) {
NSLog(@"LENGTH WAS 0");
x = -100;
}
else{
NSLog(@"LENGTH WASN'T ZERO, TRYING TO REARRANGE");
[tempDic setObject: [tempDic objectForKey:[NSString stringWithFormat:@"%d",xIncrease]] forKey:[NSString stringWithFormat:@"%d",x]];
[tempDic removeObjectForKey:[NSString stringWithFormat:@"%d",xIncrease]];
}
}
}
//[dict setObject: [dict objectForKey: @"oldkey"] forKey: @"newkey"];
//[dict removeObjectForKey: @"oldkey"];
[currentSectionArray removeObjectAtIndex:indexPath.row];
[[self.sectionArrays objectAtIndex:indexPath.section]isEqualToArray:currentSectionArray];
[self.mainDictionary setObject:tempDic forKey:[NSString stringWithFormat:@"%@",currentStringSubject]];
[[NSUserDefaults standardUserDefaults] setObject:self.mainDictionary forKey:[NSString stringWithFormat:@"mainDictionary%@",self.todayString ]];
[[NSUserDefaults standardUserDefaults]synchronize];
[tableViews deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"TEST");
NSString *currentStringSubject = [self.subjectArray objectAtIndex:indexPath.section];
NSMutableDictionary *mutDic = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"mainDictionary%@",self.todayString ]];
NSMutableDictionary *tempDir = [mutDic valueForKey:[NSString stringWithFormat:@"%@",[self.subjectArray objectAtIndex:indexPath.section]]];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if ([self.mainDictionary objectForKey:[NSString stringWithFormat:@"%@completed",currentStringSubject]]) {
}
[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
可能有多種原因,但請一一檢查;)
1)確保必須同時設置
self.tableView.delegate = self;
self.tableView.dataSource = self;
2),並且檢查這個答案(S)
3)如果您使用過任何手勢識別器,請嘗試將其刪除並檢查是否引起了問題?
4)
self.tableView.allowsMultipleSelection = NO;
self.tableView.allowsSelection = YES;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.