UITableView and Navigation Controller - ios

I am trying to do a simple Navigation controller controlled by a UITableView. Whenever I select one of the rows it is supposed to go to the next slide and animate there. Whenever I implement this code, the animation only goes halfway, then freezes, and then disappears.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
description* desc=[[description alloc] init];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.navigationController pushViewController:desc animated:YES];
}
Can anyone help? Thanks in advance.

I don't know if this is the same problem, but something similar happened to me. The problem was that the backgroundColor of the UIView of my pushed UIViewController was clear, which cause the animation to look weird because we can see the pushing UIViewController underneath.
Setting backgroundColor on the UIView of the pushed UIViewController (in my case, in white) solved the problem

Related

How to connect two view controller to one view controller using Storyboard?

I'm trying to connect two view controller into a one controller. As you can see below picture, when "plus" item is tapped the screen came and it works well. However, the other segue doesn't work properly. With my first tapping to any row, it doesn't take me to the view but after first tapping it starts taking me to the view as I wanted. I couldn't figure out why it doesn't take me to when I firstly tap any row. Here is the didSelectRowAtIndexPath code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
DovizDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
[self.navigationController pushViewController:detail animated:YES];
}
Below is my storyboard. The problem is about with the above view and it's segue.
Hope you can help me.
Thanks!
Change didDeselectRowAtIndexPath to didSelectRowAtIndexPath

tableView: didSelectRowAtIndexPath: looks awful if not setting the next viewcontroller's background color

When I tried to push a view controller using tableView: didSelectRowAtIndexPath: method, the transition did work certainly, but its animation looks quite awful; when I tapped any cell in UITableView, one third of the entire screen first became black (but the other two thirds are still UITableViewCell of the original screen!) and with a little bit of delay, the entire screen turned black.
I wonder why tableView: didSelectRowAtIndexPath: method acts in such a terrible way in terms of user-interface. Here's my code to make the transition:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] init];
People *people = [_fetchedResultsController objectAtIndexPath:indexPath];
detailViewController.title = people.type1;
[self.navigationController pushViewController:detailViewController animated:YES];
}
However, if I change the animated: to NO, the transition doesn't have any issue (in terms of UI, again; that's what I'm asking here), but it changes to the new view controller instantly (naturally, since it's what the animated:NO do in the first place).
And the answer to this strange behavior is to set backgroundColor of the second view controller BEFORE executing pushViewController: animated: method, as suggested in this question.
I wonder WHY I have to set background color before making the transition, and WHY setting its background color can resolve this UI-related issue.
I use iOS 7 and Xcode 5.
The default background colour for your new viewController is clear, so when you do an animated push you can see through the new viewController temporarily as it pushes itself on top of the navigation stack.
Setting an opaque background colour will mean that your new VC is not transparent, and thus you won't be able to see through it to the VC underneath.
However, I'd recommend you set your backgroundColor in viewDidLoad of your new viewcontroller, instead of in the one that's doing the presenting (it's not really the responsibility of your presenting viewController to do that).
Try setting a background colour of the detail view in the init method ?
[[self view] setBackgroundColor:[UIColor whiteColor]];

deselectRowAtIndexPath issue

I have just started working with tableViews, and I have 5 cells in a tableview in a viewController embedded in a navigationController. When a cell is pressed another view is pushed in. My problem is that the cell I press is selected but the selection doesn't go away. I have tried with this code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
[self.navigationController pushViewController: newViewController animated:YES];
}
The tableView is initialized in the viewDidLoad method. Still when I click a cell the new viewController is pushed in but the cell stays selected. What might be the issue here?
You've put your code in the didDeselectRowAtIndexPath - put it in the didSelectRowAtIndexPath. This is an easy mistake to make since didDeselect comes up in code completion before didSelect.
Summary :
You have tableview that is in a ViewController that is in a NavigationController
Use touch a cell
A new ViewController is push on the NavigationController Stack
User hit back and goes back to the screen where you have a tableView
That is what I understand from your question.
At this moment the cell in your tableView should still be selected in order for the user to have a reminder of the last action he as done, but you also want it to get unselected animated at the point ( the mail application is a good example of this behaviour).
So the best place to deselect the cell in your tableView is in - (void)viewDidAppear:(BOOL)animated method of the UIViewController that have the tableview inside it's view. By doing so you will let the user a chance to see the selection before it gently fade away like in mail.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:animated];
}
You can pass nil as argument of deselectRowAtIndexPath, tableView handles it gracefully.
Did you also implement tableView:didSelectRowAtIndexPath:? This method is called every time you tap a cell. So you should put your code there.
The method you are using, tableView:didDeselectRowAtIndexPath: is called whenever a cell is selected and you are tapping a different cell.
I think your problem is that you use wrong method. Change didDeselectRowAtIndexPath to didSelectRowAtIndexPath.

Pushing new view controller from UITableView on a Tab Bar application

I have an app with two bar in it.
one of the tab .xib includes UITableView, when the user select one of the cells, I want to show another UIViewcontroller (.xib file) that includes information about the his selection.
now, I've tried this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
NextViewController *nextController = [[NextViewController alloc] initWithNibName:#"NextView" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES]; [nextController changeProductText:[arryData objectAtIndex:indexPath.row]];
}
and nothing happened, the console is showing no errors at all.
what seems to be the problem?
thanks!
Nothing happened, because your self.navigationController returns nil.
For proper usage of Navigation controller, you must have at least one. For the case of TabBar application, for each tab you must associate not the UIViewController subclass, but UIViewController subclass nested in UINavigationController. That's easily done both in the .xib or in code. Just google for some tutorials.

Split View like Settings

I have created a basic Split View and instead of loading a UIView on the right hand side, I have loaded a UITableView. The UITableView is made up of UITableViewCell's and what I want to do is when I click on the Cell, it loads up another UITableView for selection much like that in the iPad settings. However I cannot the UITableView to load after selection.
Any ideas how to achieve this? I've seen similiar questions and had a look at the apple site with uitableviews but haven't been able to solve the issue as they're geared towards iphone which doesn't have the split view.
On the didSelectRowAtIndexPath i've loaded it like so which other apps have done but to no avail.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.row == 0)
{
LevelTwoController *leveltwoController = [[LevelTwoController alloc] initWithNibName:#"LevelTwoTableView" bundle:nil];
[self.navigationController pushViewController:leveltwoController animated:YES];
[leveltwoController release];
}
}
Another thing also is my leveltwoController is a UITableViewController and I just keep getting this import error literal-pointer#_OBJC#_cls_refs.
Your main view that has the TableViewController needs to be controlled by a UINavigationController, and then you could push the subsequent views onto the view stack. My guess is your current implementation is having self.navigationController be nil so nothing is happening.
If you take a look at some of the basic xcode templates that use uinavigationcontroller's you should be able to figure out the proper path.

Resources