Views duplicating ? - ECSlidingViewController - ios

I'm currently using the ECSlidingViewControllersample and I'm having a small bug while opening the same view I'm currently in.
For Example if I'm inside GudjonDaneil and I open the "drawer" and hit GudjonDaniel again the viewDidLoad method calls twice, If I open it again it calls the viewDidLoad 3 times in a row. It seems like the views are stacking above each other. I need someway of killing the class(view) once I open the view again.
Here's what happens once you click on the -UItableView
NSLog(#"Channel 1 Loading");
tableViewCellLoading = true;
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;
self.slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"firstChannel"];
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; }];
How the drawer application looks like
http://gyazo.com/f811283fadbad5b50ee4d594b6798f18

I know it's been a while since this question was asked... but here's an answer for anyone else that is looking.
The following is from my "MenuController.m" file.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.slidingViewController.topViewController.view.layer.transform = CATransform3DMakeScale(1, 1, 1);
UINavigationController *currentNav = (UINavigationController *)self.slidingViewController.topViewController;
UIViewController *theControllerYouWant = [currentNav.viewControllers objectAtIndex:([currentNav.viewControllers count]-1)];
NSString *CurrentSelectedCViewController = NSStringFromClass(theControllerYouWant.class);
if (indexPath.row == 1 && ![CurrentSelectedCViewController isEqualToString:#"PeopleTableViewController"]) {
[(UINavigationController *)self.slidingViewController.topViewController setViewControllers: [NSArray arrayWithObject: [self.storyboard instantiateViewControllerWithIdentifier:#"PeopleView"]]];
} else if (indexPath.row == 2 && ![CurrentSelectedCViewController isEqualToString:#"CompanyPickerController"]) {
[(UINavigationController *)self.slidingViewController.topViewController setViewControllers: [NSArray arrayWithObject: [self.storyboard instantiateViewControllerWithIdentifier:#"CompanyView"]]];
}
[self.slidingViewController resetTopViewAnimated:YES];
}
The basic explanation is this:
Get a reference to the current Navigation Controller
Get a reference to the Navigation Controller's top view (always the last view in its
array)
Get a string representation of that view.
Depending on which menu cell you clicked on, check if the slidingViewController's
current top view is the same that you are going to..
If it's not the same, load the proper view in to topviewcontroller
Close the menu

Related

Navigating pages in different tableview

I have created a screen containing two table views where i have successfully called the method cellForRowAtIndexPath but now am facing trouble in navigating to the other page from tableview option by using didSelectRowAtIndexPath.I think am doing some mistake and i have clearly no idea what is the next step.Can anyone guide how should i do it?? I have used this code-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView isEqual:leftTableView]) {
TattooSinglesScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooSinglesScreen"];
EyecatcherScreen *obj1=[self.storyboard instantiateViewControllerWithIdentifier:#"EyecatcherScreen"];
TattooToplist *obj2=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooToplist"];
int i=indexPath.row;
if(i==0){
[self.navigationController pushViewController:obj animated:nil];
}
else if (i==1) {
[self.navigationController pushViewController:obj1 animated:NO];
}
else if (i==2) {
[self.navigationController pushViewController:obj2 animated:NO];
}
}
else {
TattooSinglesScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooSinglesScreen"];
EyecatcherScreen *obj1=[self.storyboard instantiateViewControllerWithIdentifier:#"EyecatcherScreen"];
TattooToplist *obj2=[self.storyboard instantiateViewControllerWithIdentifier:#"TattooToplist"];
int i=indexPath.row;
if(i==0){
[self.navigationController pushViewController:obj animated:nil];
}
else if (i==1) {
[self.navigationController pushViewController:obj1 animated:NO];
}
else if (i==2) {
[self.navigationController pushViewController:obj2 animated:NO];
}
}
}
If you want to navigate from table view to another view controller don't set animated:NO.set animated:YES for navigating.But if you set animated:NO,definitely it does not navigate.So you have to do following things for navigating.
YourViewController *yourVC = (YourViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"StoryBordIdentifier"];
[self.navigationController pushViewController:yourVC animated:YES];
Also You can use in this didSelectRowAtIndexPath
[self performSegueWithIdentifier:#"segueID" sender:self];
with
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
YourViewController *vc = segue.destinationViewController;
}
Click Table Row and Go another Page
Segue or didSelectRowAtIndexPath
Making Push Segue when table row is selected
I see user3182143's answer helped, but for what it's worth I've set up a tiny demo project (now updated with two tables) to show anybody interested how it's done.
It also illustrates (as the name implies), that you can, indeed, push manually and set the animation parameter to NO, just run it in the simulator.
I can't tell why that didn't work in your original approach, pri, but my guess is that you set up your navigation view controller wrongly somehow.
For code & storyboard readability I'd recommend using segues anyways.

displaying splash screen while downloading images from server in ios

in my app i am trying to make a slider using the LWSlideShow LWSlideShow
the source of images are fetched from my server after trying the solution here i stuck with error that said unbalanced call and it means that i am presenting a modal view on a view that did not completed his animation after solving this problem by putting animation to no the splashView that i present will be dismissed before the images are downloaded here is my code for further explanation:
- (IBAction)goDownload {
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Splash"];
[self.navigationController presentViewController:vc animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *array = [#[] mutableCopy];
LWSlideItem *item = [LWSlideItem itemWithCaption:#""
imageUrl:#"http://code-bee.net/geeks/images/cover-1.jpg"];
[array addObject:item];
item = [LWSlideItem itemWithCaption:#""
imageUrl:#"http://code-bee.net/geeks/images/cover-2.jpg"];
[array addObject:item];
item = [LWSlideItem itemWithCaption:#""
imageUrl:#"http://code-bee.net/geeks/images/cover-3.jpg"];
[array addObject:item];
LWSlideShow *slideShow = [[LWSlideShow alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 120)];
slideShow.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//slideShow.delegate = self;
[self.view addSubview:slideShow];
slideShow.slideItems = array;
if ([slideShow.slideItems count] == [array count]) {
[self dismissViewControllerAnimated:YES completion:nil];
}
});
}
//
//-(void)viewWillAppear:(BOOL)animated
//{
//
// UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Splash"];
// [self.navigationController presentViewController:vc animated:YES completion:nil];
//}
- (void)viewDidLoad {
[super viewDidLoad];
[self goDownload];
}
also you can see from the code that also i try to use viewWillAppear same thing happened what i want is when the images are downloaded the splashView need to be dismissed i dont know what i am doing wrong
Running that code from a VC anytime before viewDidAppear (like viewDidLoad, viewWillAppear) will cause the problem you describe. But you probably don't want the slide show view to appear - even for an instant - until you're done fetching the assets. This is a common problem.
The solution is to realize that the "splash screen" and the network tasks aren't just preamble, they are as much a part of your application as the slide show.
EDIT
Make that Splash vc the app's initial view controller in storyboard. Right now, the slide show vc probably looks like this:
Uncheck the "Is Initial View Controller" checkbox, find your splash view controller (in the same storyboard, I hope) and check it's box to be the initial view controller. Now your app will start up on the splash vc, like you want it.
When the splash vc done, it can present the slide show vc, or it can even replace itself (with the slide show ) as the app window's root.
To replace the UI, I use variations of this snippet...
// in the splash vc, after all of the asset loading is complete
// give what used to be your initial view controller a storyboard id
// like #"MySlideShowUI"
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"MySlideShowUI"];
UIWindow *window = [UIApplication sharedApplication].delegate.window;
window.rootViewController = vc;
[UIView transitionWithView:window
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:nil
completion:nil];

Two view controllers use same table view

I'm new to iOS development. I want to know how to pass back data from same tableview to two different view controller.
This is my didselectrow method:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
sendarea = [tableData objectAtIndex:indexPath.row];
Step2ClassifiedViewController *parentViewC = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 2];
parentViewC.areareceive = sendarea;
[self.navigationController popViewControllerAnimated:YES];
}
But this is only for one view. I have another view also need to pass back the data if i use the same table. Is that possible? or do i just need to create another table?.
You can use same table. Only you need change the data source. And can call in each didSelectRowAtIndexpath
This is just like, A taxi driver carries passenger by his one taxi. When his taxi is empty,he can carries passenger.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
sendarea = [tableData objectAtIndex:indexPath.row];
if(state == 1){
Step2ClassifiedViewController *parentViewC = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 2];
parentViewC.areareceive = sendarea;
[self.navigationController popViewControllerAnimated:YES];
}
else if (state == 2){
//get your other View Controller and set data before pop to that view controller.
NSArray *viewControllers = [[self navigationController] viewControllers];
for(UIViewController *vc in viewControllers){
if([vc isKindOfClass:[OtherViewController class]]){
OtherViewController *otherVC = (OtherViewController*)vc;
otherVC.areareceive = sendarea;
[[self navigationController] popToViewController:otherVC animated:YES];
}
}
}
else{
//load any View Controller you want
}
}
Based on your question and the comments, I assume that you want to load different View Controllers based on your different state and pass along data.
The above is one way of doing that. However, you could also use delegation for your purpose, it would be a good programming practise.

didSelectRowAtIndexPath or prepareForSegue to use?

i want to be able to select a item in my tableview and get to the correct view.
say i have two items in my uitableview. one has a value of ubuntu other has a value of arch- in my plist from arraA i have a SystemID which holds the text Ubuntu/Arch, never both
now when i select the one with ubuntu i want it to push to a new view where ubuntu stuff is
and if i go back and select arch it will again push me to a view where arch stuff is
so far i made this and it's not working as intended:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *segueName = nil;
if ([[arrayA valueForKey:#"SystemID"]isEqualToString:#"Ubuntu Linux"]) {
ActionViewController *controller = [[ActionViewController alloc] initWithNibName:#"Ubuntu Linux" bundle:nil];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
[self.navigationController pushViewController:controller animated:YES];
}
else if ([[arrayA valueForKey:#"SystemID"]isEqualToString:#"Arch Linux"]) {
ActionViewController *controller = [[ActionViewController alloc] initWithNibName:#"Arch Linux" bundle:nil];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
[self.navigationController pushViewController:controller animated:YES];
}
[self performSegueWithIdentifier: segueName sender: self];
}
also tried prepare forsegue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([arrayA valueForKey:#"Arch Linux"])
{
ActionViewController *controller = (ActionViewController *)segue.destinationViewController;
NSIndexPath *indexPath = [self.mainTableView indexPathForSelectedRow];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
NSLog(#"hostname = %#", controller.Serverinfo);
}
if ([arrayA valueForKey:#"Ubuntu Linux"]) {
ActionViewController *controller = (ActionViewController *)segue.destinationViewController;
NSIndexPath *indexPath = [self.mainTableView indexPathForSelectedRow];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
NSLog(#"hostname = %#", controller.Serverinfo);
}
}
arrayA is a NSMutableArray that read from a plist that you can see here
Replace your method to:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([arrayA[indexPath.row][#"SystemID"]isEqualToString:#"Ubuntu Linux"]) {
//ActionViewController *controller = [[ActionViewController alloc] initWithNibName:#"Ubuntu Linux" bundle:nil];
// Make sure you replace Storyboard with your storyboard name
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
ActionViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"Ubuntu Linux"];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
[self.navigationController pushViewController:controller animated:YES];
}
else if ([arrayA[indexPath.row][#"SystemID"]isEqualToString:#"Arch Linux"]) {
ActionViewController *controller = [[ActionViewController alloc] initWithNibName:#"Arch Linux" bundle:nil];
controller.Serverinfo = [arrayA objectAtIndex:indexPath.row];
[self.navigationController pushViewController:controller animated:YES];
}
}
You don't need to call [self performSegueWithIdentifier: segueName sender: self]; in didSelectRow because you already push your view in didSelectRow method. If you call it you puts the view twice.
Ooh boy, you're off in the weeds.
First, stop talking about pushing a "view." The term view and view controller are NOT interchangeable. A view is an object that appears on the screen. A view CONTROLLER is an object that manages a collection of views (usually the entire screen.)
You push a view controller, not a view. The view controller then displays it's content view on the screen.
Now, as to your code.
The if statement in your tableView:didSelectRowAtIndexPath: method is messed up.
if ([[arrayA valueForKey:#"SystemID"]isEqualToString:#"Ubuntu Linux"])
You don't want to use valueForeKey on an array. That method attempts to call valueForKey on every object in your array, and what it returns is an array of the results.
Arrays are indexed by a numeric index, not a key. You want an array as the data source for a table view.
What you want to do is to fetch the object at your selected row from your array.
In order to help you further, though, you need to explain what you have stored in your arrayA. Is it an array of dictionaries? An array of strings?
Also, you are mixing NIB based view controller code with storyboard code. You can certainly use both in the same program if you need to, but as a beginner you probably should not.
In your tableView:didSelectRowAtIndexPath method you're creating a view controller with initWithNibName, pushing it, and then calling performSegueWithIdentifier. You want to do one or the other, not both.
Use storyboard with prepareForSegue

UISplitViewController push multiple detail views iPad?

i have a requirement to load multiple viewControllers on detailViewController on a splitView. somethingLike
when the alarm is on , so that i can push the related view controller on detailView. left side view is a uitableview.
my code is here on AppDelegate.m
#import "splitDetailViewController.h"
#import "splitTableViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
splitTable=[[splitTableViewController alloc]initWithStyle:UITableViewStyleGrouped];
UINavigationController *splitTableNav=[[UINavigationController alloc]initWithRootViewController:splitTable];
splitDetails=[[splitDetailViewController alloc]initWithNibName:nil bundle:nil];
UINavigationController *splitDetailNav=[[UINavigationController alloc]initWithRootViewController:splitDetails];
self.splitViewController.delegate=splitDetails;
splitViewController=[[UISplitViewController alloc]init];
splitViewController.viewControllers=[NSArray arrayWithObjects:splitTableNav,splitDetailNav, nil];
[self.window addSubview:splitViewController.view];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
sorry, this is the first time am developing iPad apps, am little bit confused about how to use splitview. how will i call the multiple viewControllers on detail view. for timer, alarm,share , each have different view controllers.
hope i will get some help!
I was searching for the solution to a similar problem. In my case i wanted tableview to link to multiple detailviews depending on the selection. I could overlay the data on one viewcontroller but was seeking a better solution. Here is what i did. Its simple and works much better then some of the complex and outdated options i found so far.
I simply gave a storyboard ID in the identity inspector to the viewcontroller that i wanted showing up in the detailview ("second") and upon didSelectRowAtIndexPath i simply added:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"second"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
}
So when someone presses a cell in the master view, the detail view is pushed.
A simple if statement can switch which view is shown:
if ([[self.selfRootMenuArray objectAtIndex:indexPath.row] isEqual: #"Second Choice"]) {
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"second"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
} else if ([[self.selfRootMenuArray objectAtIndex:indexPath.row] isEqual: #"First Choice"]) {
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"first"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
};
You could simply use buttons, switches or anything else instead of a table view but the point is that by adding a "Storyboard ID" in the "Identity Inspector"
and simply instantiating the view controller by referencing the "Storyboard ID" and then pushing it to the split view controller at index 1 (detail side) its simple and quick
TimeDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"second"];
[[self.splitViewController.viewControllers objectAtIndex:1] pushViewController:detail animated:YES];
Hope it helps
okay, myself found one solution, it works fine
http://kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/
thankyou
This is my Solution, hope it helps : https://github.com/selfdealloc/MultipleDetailViewsUsingStoryboards

Resources