data from plist is loading detail view in a dark screen - cocoa-touch

So i have set a plist and everytime someone click on the cell in table view i want it to load in the detail view. The only problem is that when it is clicked it loads a dark black screen with nothing on it. Any suggestions?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Index Selected,%d",indexPath.row);
WebViewController *modalView = [[WebViewController alloc] init];
NSString *urltoPass = [NSString stringWithString:[[tableData objectAtIndex:indexPath.row]objectForKey:#"cellSubtitle"]];
modalView.urlString = [[NSString alloc] initWithFormat:#"http://%#",urltoPass];
modalView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:modalView animated:YES completion:nil];
}

You forgot to actually present the new view controller. You have to add the following line to the bottom of your didSelectRowAtIndexPath: method.
[self presentViewController:modalView animated:YES completion:nil];
Also, you can remove the line below entirely as it doesn't do anything in its current form.
[self.navigationController modalTransitionStyle];

Related

MGSplitViewController as Modal not working correctly

I am trying to use an MGSplitViewController, but rather than having it set as the rootViewController, I want it to show modally. This is the code I am using so far
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath
{
if(splitViewController == nil)
{
self.splitViewController = [[MGSplitViewController alloc] init];
self.rootViewController = [[RootViewController alloc] init];
self.detailViewController = [[DetailViewController alloc] init];
}
[splitViewController setViewControllers:[NSArray arrayWithObjects:rootViewController, detailViewController, nil]];
if (NO) { // whether to allow dragging the divider to move the split.
splitViewController.splitWidth = 15.0; // make it wide enough to actually drag!
splitViewController.allowsDraggingDivider = YES;
}
splitViewController.delegate = detailViewController;
[rootViewController performSelector:#selector(selectFirstRow) withObject:nil afterDelay:0];
[detailViewController performSelector:#selector(configureView) withObject:nil afterDelay:0];
[self presentViewController:splitViewController animated:YES completion:nil];
}
This works almost fine, but the buttons in the detailViewController do not work. They do nothing. Also, when I click a button in the left panel, the text doesn't change in the detailViewController as it does in the same project.
Am I missing something?
I'm also working with MGSplitViewController, but it sounds to me like you need to set up some communication between your master and detail views. If you look at the demo project, you can see they use delegates to that effect.

detailview screen can not open with pushViewController in a tableview

I have a tabbar in my project and each tab bar has a tableview.
I want to open a detail screen when click a row in a tableview as follows. But nothing happens.
Where's the mistake I'm doing. How should I set up a logic.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:#"DetailScreen" bundle:nil];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
}
There are many possible reasons nothing is happening when you click on a cell.
Put a break point in this method. Is It even being called?
After the App has stopped at the breakpoint, go to the console type po detail after the instance is initialised. Make sure it's not (null)
Also try typing po [self navigationController] to check whether the navigation controller exists.
You've probably not got a navigation controller. How are you creating the tabbarcontroller? in interface builder or through code in the AppDelegate's didFinishLaunchingWithOptions: method?
Have you done this?
YourViewController *yourVC = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourVC];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, nil];
try this,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailScreen *detail = [[DetailScreen alloc] init];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
}
I guess you don't have a navigation controller so
[self.navigationController pushViewController:detail animated:YES];
will not work.
use
[self.view addSubview:detail.view]
or
[self presentModalViewController:detail animated:YES];
instead
If your project is UITabBarViewController based application, i dont think your can navigate to another view using pushViewController unless you have navigationController in your project.
Add your view controller(your table view containing controller) into navigation controller and then start using
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:#"DetailScreen" bundle:nil];
[self.navigationController pushViewController:detail animated:YES];
[self.navigationController pushViewController:detail animated:YES];
Instead move your detail push code to another method and call:
[self performSelector:#selector(myMethod:) withObject:nil]

Tablecell click short delay

When I click on table cell, there's a short delay of 1-2 second before it loads the next view. I've seen some apps that show an activity indicator during that time and that's what I'd like to do. I've added one like this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
spinner.frame = CGRectMake(200,200,200,200);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = spinner;
[spinner startAnimating];
[spinner release];
VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:#"VenueViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:vviewcontroller animated:YES];
[vviewcontroller release];
vviewcontroller = nil;}
however this also appears with a delay, and just before the next view is showing. It seems the app freezes for 1-2 seconds after clicking on the table cell so it doesn't even show the activity indicator.
I think the secret is that you should call load method using a performSelector method. Another tip is hiding or showing the activity so it won't consume time this operation.
So this could be a pseudocode of that
Inside your ViewController class definition:
IBOutlet UIActivityIndicatorView *spin; // created in view and hidden
In your implementation...
-(void) load{ // your code
VenueViewController *vviewcontroller = [[VenueViewController alloc] initWithNibName:#"VenueViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:vviewcontroller animated:YES];
[vviewcontroller release];
vviewcontroller = nil;
spin.hidden=YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
spinner.hidden=NO;
[self performSelector:#selector(load) withObject:nil afterDelay:0];
}
Hope it helps.

PopOver and Tableviews

Quick question on popovers, i seem not grasp a way of closing a popview when i select something from it (tableview)
so i have a list items on a tableview which popup using a UIPopoverController so when i select an item i'd like to the popove to fade away.
MainViewController
- (IBAction)popoverFontName:(id)sender
CGRect popoverRect = [self.view convertRect:[popoverFontName frame]
fromView:[popoverFontName superview]];
TitleController *titleC=[[TitleController alloc]init];
popup =[[UIPopoverController alloc]initWithContentViewController:titleC];
[popup presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popup setPopoverContentSize:CGSizeMake(50.0, 300.0)];
[titleC release];
}
TitleController
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedLang = [titleList objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
MyDetViewCont *myDetViewCont = [[MyDetViewCont alloc] initWithNibName:#"myDetViewCont" bundle:[NSBundle mainBundle]]; // view controller instance
}
On the title contoller i dont know how to dismiss the popover
You can call dismissPopoverAnimated: on the popoverController. You should keep an instance of your popover as an instance variable in order to dismiss from the UITableViewDelegate methods.

didSelectRowAtIndexPath problem

I have a problem that I had working in a test but now in a bigger application I can't seem to sort out.
First of I have a view that has six button each loads a different view I am using:
- (IBAction)showInfo2:(id)sender {
InfoViewController *Infocontroller = [[[InfoViewController alloc] initWithNibName:#"InfoView" bundle:nil] autorelease];
Infocontroller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:Infocontroller animated:YES];
}
This seems to be working fine, and loads the next section, in this case 'infoview'.
I then load a tableview and fill it full f data from an xml feed, this again is now working, (although was not an easy task for me!).
The problem comes when I know try and use:
Nothing seems to happen, ie, the new view is not loaded.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
SubInfoViewController *subInfoViewController = [[SubInfoViewController alloc] initWithNibName:#"SubInfoView" bundle:nil];
[self.navigationController pushViewController:subInfoViewController animated:YES];
[subInfoViewController release];
}
I know its being called because this works:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *message = [[NSString alloc] initWithFormat:#"You selected a row"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Row Selected" message:message delegate:nil cancelButtonTitle:#"Yes I did" otherButtonTitles:nil];
[alert show];
[message release];
[alert release];
}
Any help more than welcome, and please be gentle newbie :)
You're view is probably push into navigation stack but you can't see it because your parent view is modal.
You can't try to display your SubInfoViewController like this :
SubInfoViewController *subcontroller=[[SubInfoViewController alloc] initWithNibName:#"SubInfoViewController" withBundle:nil];
[self presentModalViewController:subcontroller animated:YES];
[subcontroller release];
If you want to keep a navigation logic in your app, you should not display your InfoViewController modally but present it in a common way in your navigation stack.
You can try to dismiss your modal view before pushing your SubViewController. In this case you must do something like this :
SubInfoViewController *controller=[[SubInfoViewController alloc] initWithNibName:#"SubInfoViewController" bundle:nil];
[self.parentViewController pushViewController:controller animated:YES];
[self dismissModalViewControllerAnimated:YES];
[controller release];
You'll receive a warning because parentViewController may not respond to pushViewController: animated: but with a NSLog you'll see that your parentViewController is actually a UINavigationController.
Hope this helps !
What exactly is the problem? Your code looks fine at first glance.