Navigation title is not changing in iOS 7 - iphone

I have done the following code previously on in my app. It is working good with all the iOS other than iOS7. I am changing the navigation title in didSelectRow method but it is not changing my navigation bar title in iOS 7. I create a new controller on run time in didselectrow and giving it a title in this line nextController.title = [dataDict objectForKey: kNestedDataKey_title];
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
NSLogDebug();
NSDictionary *dataDict = [self.data objectAtIndex: indexPath.row];
NSString *classNSString = [dataDict objectForKey: kNestedDataKey_class];
UIViewController *nextController = NULL;
nextController = [[NestedTableViewController alloc] initWithNibName: nil bundle: nil];
[self.navigationController pushViewController: nextController animated: YES];
((NestedTableViewController *) nextController).data = [dataDict objectForKey: kNestedDataKey_data];
nextController.title = [dataDict objectForKey: kNestedDataKey_title];
[nextController release];
}
Note: It is working fine in all the iOS other than iOS 7

I notice a strange behavior in iOS 7, that view loads in memory bit late. so when you are setting title, it is possible label for title is not yet created. SO use this statement before setting tile. this will make sure that your View is created and in memory.
[nextController view];
after this set title
nextController.title = #"Title";
Good luck

Try This code
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
NSLogDebug();
NSDictionary *dataDict = [self.data objectAtIndex: indexPath.row];
NSString *classNSString = [dataDict objectForKey: kNestedDataKey_class];
NestedTableViewController *nextController = NULL;
nextController = [[NestedTableViewController alloc] initWithNibName: nil bundle: nil];
nextController.data = [dataDict objectForKey: kNestedDataKey_data];
nextController.title = [dataDict objectForKey: kNestedDataKey_title];
[self.navigationController pushViewController: nextController animated: YES];
[nextController release];
}

Related

iOS app freezes after UITableView search

I am a beginner to iOS development and am having trouble finding the cause for this issue.
I have a simple app with a Master and DetailView controllers. The Master View contains an UITableView with a SearchController. Selecting any row on the UITableView will transition to the detailview.
The app freezes when I perform the following sequence
Launch app
Pull down the search bar
Enter text
Select a row from the search results
Select back from the detail view
Now the app freezes after the ViewDidLoad method of the MasterView is loaded. I can't find anything in the system.log.
Here's the code from the MasterViewController
- (void)viewWillAppear:(BOOL)animated {
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
[self.tableView setContentOffset:CGPointMake(0,40)];
self.tableView.tableHeaderView = self.searchBar;
// Create and configure the search controller
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *months = #"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
feeds = [months componentsSeparatedByString:#","];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(#"numberOfRowsInSection");
if(tableView == self.tableView)
{
return feeds.count;
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"SELF like %#", self.searchBar.text];
self.filteredFeeds = [feeds filteredArrayUsingPredicate:predicate];
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"];
}
cell.textLabel.text = [feeds objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
NSDate *object = _objects[indexPath.row];
self.detailViewController.detailItem = object;
}
[self performSegueWithIdentifier: #"showDetail" sender: self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}
I have uploaded the entire project at the location below.
https://www.dropbox.com/s/yok9vngzv143npa/search.zip
Any kind of assistance is appreciated.
I can not able to run your program because version issue of iOS.
But i seen your code. I suspect on 1 point on following code,
- (void)viewWillAppear:(BOOL)animated {
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
[self.tableView setContentOffset:CGPointMake(0,40)];
self.tableView.tableHeaderView = self.searchBar;
// Create and configure the search controller
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
}
You create/allocate UISearchBar and UISearchDisplayController again and again while you get back from DetailViewController to MasterViewController, these may be cause of your app freezing.
"viewWillAppear" called before the receiver’s view is about to be added to a view hierarchy and before any animations are configured for showing the view.
"viewDidLoad" called after view controller has loaded its view hierarchy into memory.
I suggest you place your one time allocations view code in viewDidLoad method.
For more information go through this doc https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/viewDidLoad

iOS UITableViewController didSelectRowAtIndexPath not loading another UITableViewController

I have a UITableViewController working just fine with all the content when I tap on one of the cells didSelectRowAtIndexPath is being call but doesn't go to the next UITableViewController. Here is my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewHeadersController *detailViewController = [[ViewHeadersController alloc] initWithNibName:#"ViewHeadersController" bundle:nil];
NSArray *resultsData = [_response objectForKey:#"results"];
detailViewController.urlHeaders = [[resultsData objectAtIndex:indexPath.row] objectForKey:#"url"];
[self.navigationController pushViewController:detailViewController animated:YES];
}
I know didSelectRowAtIndexPath is responding because I see the output of the NSLog.
Any of you knows what is going on or why the uitablevicontroller is not switching to the next UITableViewController?
I'll really appreciate your help
I change the line where is navegationController:
ViewHeadersController *detailViewController = [[ViewHeadersController alloc] initWithNibName:#"ViewHeadersController" bundle:nil];
detailViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
NSArray *resultsData = [_response objectForKey:#"results"];
detailViewController.urlHeaders = [[resultsData objectAtIndex:indexPath.row] objectForKey:#"url"];
[self presentViewController:detailViewController animated:YES completion:nil];

How to pass a tableview cell value to another page(uiviewcontroller)?

Ha ii,everybody i have a tabeview cell containing some values.if the user tap one of the cell a subview with buttons appears and there in popoup i have a button named save.My need is when the user tap the save button it redirect to the save page with the value of the cell,and show it in the textview of the save page.This is my code for redirecting to save page.
-(IBAction)buttonclick{
StatusViewController *detailViewController = [[StatusViewController alloc] initWithNibName:#"StatusViewController" bundle:nil];
detailViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:detailViewController animated:YES];
[UIView commitAnimations];
[detailViewController release];}
Store the string value of the cell in the NSString value in the class.
If you want the string value from the last selected table view cell. Get the string value from the delegate method,
NSString *localStringValue;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
localStringValue = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
}
Create a NSString property in the StatusViewController.
#interface StatusViewController : UIViewController {
}
#property(nonatomic, retain) NSString *yourStringProperty;
alter your code as below,
StatusViewController *detailViewController = [[StatusViewController alloc] initWithNibName:#"StatusViewController" bundle:nil];
detailViewController.yourStringProperty = localStringValue;
in StatusViewController class you could access the string value by using,
self.yourStringProperty
Use the delegate concept for the communication between two classes.
The Basics of Protocols and Delegates
How do I set up a simple delegate to communicate between two view controllers?
NSUInteger row = [indexPath row];
NSString value = [listOfItems objectAtIndex:row]; //use this code
StatusViewController *detailViewController = [[StatusViewController alloc] initWithNibName:#"StatusViewController" bundle:nil];
detailViewController.label=value;
detailViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:detailViewController animated:YES];
[UIView commitAnimations];
[detailViewController release];
StatusViewController.h file
NSString *label;
#property (nonatomic, assign) NSString *label;
StatusViewController.m
-(void) viewdidload{
NSLog(#"%#",label);
}

Grouped Table View Obj-C

I followed the tutorial here and was wondering how to make the table appear grouped.
ex:
group1 contains Subview One and Subview Two
group2 contains Subview Three
I switched the type in interface builder but that only shows one group.
Thanks,
Adam
Sidenote* I am a completely new at objective c, hence the tutorial.
EDIT
I thought it might be helpful to put up the piece of code
#import "RootViewController.h"
#import "SubViewOneController.h"
#import "SubViewTwoController.h"
#implementation RootViewController
#pragma mark -
#pragma mark View lifecycle
-(void)awakeFromNib {
views = [[NSMutableArray alloc] init];
SubViewOneController *subViewOneController = [[SubViewOneController alloc] init];
SubViewTwoController *subViewTwoController = [[SubViewTwoController alloc] init];
//Subview 1
subViewOneController.title = #"Subview One";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
#"Subview One", #"title",
subViewOneController, #"controller",
nil]];
[subViewOneController release];
//Subview 2
subViewOneController = [[SubViewOneController alloc] init];
subViewOneController.title = #"Subview Two";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
#"Subview Two", #"title",
subViewTwoController, #"controller",
nil]];
[subViewOneController release];
//Subview 3
subViewOneController = [[SubViewOneController alloc] init];
subViewOneController.title = #"Subview Three";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
#"Subview Three", #"title",
subViewOneController, #"controller",
nil]];
[subViewOneController release];
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = #"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
self.title = #"Basic Navigation";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [views count];
}
//
//I think it goes somewhere in here
//
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier];
}
cell.text = [[views objectAtIndex:indexPath.row] objectForKey:#"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:#"controller"];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
- (void)dealloc {
[views dealloc];
[super dealloc];
}
#end
Ok so you are correct it does go into your cellForRowAtIndexPath: you will be looking to do something like:
if ([indexPath section] == 0) {
//stuff for first section.
}
if ([indexPath section] == 1) {
//stuff for second section.
}
You will need to also deal with how your are configuring the cell from your array. The sections row numbers start with 0. The same thing with didSelectRowAtIndexPath:
If you don't deal with the section where you set the cell.text you will end up with
Subview One
Subview Two
Subview One
I recommend getting the iPhone Programming (The Big Nerd Ranch Guide)
In Interface Builder, choose your UITableView object and choose Grouped as the style.
If you are programmatically creating it, use the initWithStyle: UITableViewStyleGrouped.
EDIT:
if (section == 0) { /* your first section */ }
if (section == 1) { /* your second section */ }
This is all controlled by your UITableViewDataSource. The numberOfSectionsInTableView: method controls how many groups there are, and tableView:numberOfRowsInSection: controls how many rows are in each group.
Your tableView:cellForRowAtIndexPath: on the UITableViewDelegate gets an NSIndexPath object; indexPath.section tells you which group and indexPath.row tells you which row in the group. The cell you return really has no idea which group it is in or which row in the group it is, it's all controlled by the fact that you return it for a particular indexPath when tableView:cellForRowAtIndexPath: is called.

Pointer reference?

I'm pretty new to iPhone application development and I'm doing well so far. But at one point my App doesn't do what it is intend for...
It's a tableview based app and i'm pushing a new controller onto the stack to get some Userinput, but when the controller is popped again the data is somehow gone. Perhaps I've missunderstood something with the pointers??
rootviewcontroller.m:
edit = [fields objectAtIndex: indexPath.row];
listView.element = edit;
[self.navigationController pushViewController: listView animated:YES];
ListView.m:
element.value = [list objectAtIndex: indexPath.row];
[self.navigationController popViewControllerAnimated:YES];
so what am I doing wrong?
Thanks for your help
edit:
the value field is shown in the tableview with the cellForRowAtIndexPath method:
if (indexPath.section == 0) {
UILabel *title = (UILabel*) [cell viewWithTag:1];
UILabel *detail = (UILabel*) [cell viewWithTag:2];
ListElement *l = [fields objectAtIndex: indexPath.row];
title.text = l.name;
detail.text = l.value;
If the data is "gone" means "it's not shown after returning to root view" it can probably be fixed by
- (void) viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}
put into RootViewController.