I have a UITableView
which when you select a row, it will lead you into the "details" of the selected row. However, the first time I click the row, it goes into the prepareForSegue
method, without calling didSelectRowAtIndexPath
. When I push the back button on the detail view, the app goes back, and if I select the row again, the method will be called.
I'm NOT using the didDeselectRowAtIndexPath
.
This patter will continue and I can't figure out why. When I load my data, I do call [tableview reloadData]
.
I have also tried to add self.TagsTableView.allowsMultipleSelection = YES;
to my viewDidLoad
method.
Here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
self.bluetoothManager = [[BlueToothLEManager alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableView:) name:@"ScanComplete" object:nil];
self.Tags = self.bluetoothManager.Tags;
NSLog(@"Fetch Tags: %@", self.Tags);
}
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [fetchTagsTableView dequeueReusableCellWithIdentifier:@"tagCell"];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"tagCell"];
}
FetchTag* newTag = [fetchTags objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %d", newTag.tagName, indexPath.row];
cell.detailTextLabel.text = [newTag.tagUUID UUIDString];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedTagFromTable = [fetchTags objectAtIndex:indexPath.row];
[TagsTableView deselectRowAtIndexPath:indexPath animated:YES];
}
...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
if([[segue identifier] isEqualToString:@"DetailView"]){
TagDetailViewController* ftdvc = [segue destinationViewController];
[ftdvc setSelectedTag:selectedTagFromTable];
}
// Pass the selected object to the new view controller.
}
-(void)reloadTableView:(NSNotification*)notif{
NSLog(@"Reloading Table View");
NSLog(@"Fetch Tags: %@", self.Tags);
[self.TagsTableView reloadData];
}