I’m new to iOS and Objective-C. I have an application that displays a table view, and opens a new view when click the user clicks on a row.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailViewController *detailController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
[detailController changeSubjectText:[subject_data_Array objectAtIndex:indexPath.row]];
//navigationController = [[UINavigationController alloc] initWithRootViewController:detailController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
}
In my detail view I have coded:
-(IBAction)closeDetail:(id)sender {
NSLog(@"closeDetail");
[self.view removeFromSuperview];
}
But it’s not working. Can anyone help?
Can anyone help me?
how i can close view?
download my code in –> http://www.vasuta.com/ios/multiview2.zip
open build and run click one row in “Bulletin Board” DetailView it’s open click Close …..
why DetailView is not full screen and why can’t close detail view?
i open it wrong or i close it wrong
help me please
didSelectRowAtIndexPath you can see in “GadgetBulletinsTVContoller.m” and close command you can see in “DetailViewController.m”
Thank you very much
ps. sorry for my english skill 🙁
Why are you creating that window object and why are you trying to add your subview to it?
if you want to add a subview you should add it to the parent, the tableview or the parent of the tableView.
a better idea would be to push a new view controller on the stack that would display the info you want to show.
Here is a tutorial that shows how to push a new view controller when selecting a cell in a tableview tutorial link .
EDIT:
in MultipleAppDelegate – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions should look like below:
In GadgetBulletinsTVContoller.h declare a protocol like below:
and a delegate property:
In GadgetBulletinsTVContoller.m synthesize the delegate.
– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
should look like this:
In FirstViewController.m tell the controller to implement the GadgetBulletinsTVControllerDelegate like this:
and implement the GadgetBulletinsTVControllerDelegate’s methods:
In FirstViewController.h declare a protocol like below:
and declare a delegate property like below(don’t forget to synthesize in .m file):
In MultipleViewController.xib select the FirstViewController screen and in outlets drag from the delegate to the fileOwner for setting the value of the delegate to the MultipleViewController(you can do this in code if you want to).
In MultipleViewController.m tell the MultipleViewController to implement the FirstViewControllerDelegate protocol like below:
and implement the protocol method:
In DetailViewController modify the closeDetail method to look like this:
and voila, Your GadgetBulletinsTVController items details are pushed. You need to do the same steps for the other controllers from where you want to show details.