In first place I would like to say that I'm only making this question, because I would like to understand what is happening.
I opened an old Xcode project (a very simple one) in a fresh installation on Xcode5. When I realize that it doesn't work on iOS 7. Why? Don't know..
I saw some other questions, didn't get any useful answer, so I made a simple test.
In the UITableViewController
all works fine except on didSelectRowAtIndexPath
Check it out
RootViewController.h:
@interface RootViewController : UITableViewController
@property (strong, nonatomic) NSMutableArray *items;
@end
RootViewController.m In viewDidLoad I init the array (with some strings).
Implement the dataSource and delegate methods (and yes I set the delegate and dataSource to the tableView)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [_items objectAtIndex:indexPath.row];
return cell;
}
The problem is here:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here, for example:
// Create the next view controller.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
// Push the view controller.
[self.navigationController pushViewController:detailViewController animated:NO];
detailViewController.detailLabel.text = [_items objectAtIndex:indexPath.row];
}
DetailViewController
is a simple UIViewController:
(yes, I set the IBOutlet on nib file)
@interface DetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@end
The problem is that this doesn't work on iOS7, the label in DetailViewController
doesn't get updated. I try to set the label text before and after of pushViewController
.
This works on all previous versions of iOS.
Why is not working on iOS 7 ??
The only way I get this working is, like I saw on this other question:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here, for example:
// Create the next view controller.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
// Push the view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
detailViewController.detailLabel.text = [_items objectAtIndex:indexPath.row];
});
}
Can somebody help me out to understand what is going on here??
Thanks!
_
EDIT
it also works like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here, for example:
// Create the next view controller.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
// Push the view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
if (detailViewController.view) {
// do notihing
}
detailViewController.detailLabel.text = [_items objectAtIndex:indexPath.row];
}