I have a TableViewCell where there is a button Zoom Button. When I click to the Zoom button the view will be navigation to PlayerViewController.
(https://www.dropbox.com/s/ikmj4vdfc407ldy/customcell.png)
Here is my Code for the play Button.
-(IBAction)downloadAction:(id)sender
{
BookPlayerViewController *bookPlayerViewController=[BookPlayerViewController alloc];
[self.navigationController pushViewController:bookPlayerViewController animated:YES];
}
How can I solve this problem?. I am implementing the project using Nib instead of storyboard.
you are not initializing the nib Name. You need to initialize your BookPlayerViewController with the NibName in order to show it,
Using IB:
BookPlayerViewController *vcBookPlayerViewController = [[BookPlayerViewController alloc]
initWithNibName:#"BookPlayerViewController" bundle:nil];
Using Storyboard:
BookPlayerViewController *vcBookPlayerViewController = [storyboard
instantiateViewControllerWithIdentifier:#"BookPlayerViewController"];
I created an outlet property in the tableviewcell class
#property (retain, nonatomic) IBOutlet UIButton *zoomButton;
Then I add the target in the superclass in tableviewCellForRowAtIndex method
[cell.zoomButton addTarget:self action:#selector(navigateAction:) forControlEvents:UIControlEventTouchUpInside];
Then I take IBAction of navigateAction I wrote those actions required to navigate from one ViewController to Another ViewController.
-(IBAction)navigateAction:(id)sender
{
*UIButton *btn = (UIButton *)sender;
int indexrow = btn.tag;
NSLog(#"Selected row is: %d",indexrow);
currentBook = [[bookListParser bookListArray] objectAtIndex:indexrow];
KitapDetayViewController *kitapDetayViewController;
if(IS_IPHONE_5)
{
kitapDetayViewController = [[KitapDetayViewController alloc] initWithNibName:#"KitapDetayViewController" bundle:Nil];
}
else
{
kitapDetayViewController = [[KitapDetayViewController alloc] initWithNibName:#"KitapDetayViewController_iPhone4" bundle:Nil];
}
kitapDetayViewController.bookId=currentBook.bookId;
kitapDetayViewController.detailImageUrl = currentBook.detailImageUrl;
kitapDetayViewController.bookAuthor = currentBook.bookAuthor;
kitapDetayViewController.bookName = currentBook.bookName;
kitapDetayViewController.bookDescription = currentBook.bookDescription;
kitapDetayViewController.bookNarrator=currentBook.bookNarrator;
kitapDetayViewController.bookOrderHistory=currentBook.bookOrderDate;
int byte=[currentBook.bookSizeAtByte intValue];
int mb=byte/(1024*1024);
NSString *mbString = [NSString stringWithFormat:#"%d", mb];
kitapDetayViewController.bookSize=mbString;
kitapDetayViewController.bookOrderPrice=currentBook.priceAsText;
int second=[currentBook.bookDuration intValue];
int minute=(second/60)%60;
int hour=(second/3600)%60;
int sec = second % 60;
NSString *formattedTime = [NSString stringWithFormat:#"%d:%d:%d", hour, minute, sec];
kitapDetayViewController.bookDuration=formattedTime;
kitapDetayViewController.chapterNameListArray=self.chapterNameListArray;
// [[bookListParser bookListArray ]release];
[self.navigationController pushViewController:kitapDetayViewController animated:YES];*
}
This way I have solved the problem.
try it this way if you're loading nib of nextview
BookPlayerViewController *vcBookPlayerViewController = [[BookPlayerViewController alloc] initWithNibName:#"BookPlayerViewController" bundle:nil];
[self.navigationController pushViewController:vcBookPlayerViewController animated:YES];
you missed the nib check out this code..
-(IBAction)downloadAction:(id)sender
{
BookPlayerViewController *bookPlayerViewController=[BookPlayerViewController alloc]initWithNibName:#"BookPlayerViewController" bundle:nil];;
[self.navigationController pushViewController:bookPlayerViewController animated:YES];
}
Related
I want to make one app and it include form submition . In this i create one new project by single view application. In this firstViewController I have put button and by pressing it , it redirect to secondViewController.
In this i have a form. and want to take data from user and by submit button i want to redirect this to thirdViewController and want to print the form data on thirdViewController.
In firstViewController.m file i have written
-(IBAction)nextVCButton:(id)sender
{
SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
NSLog(#"name : %#",self.nameTextField.text);
tempView.fullName = self.nameTextField.text;
[tempView setFullName:self.fullName];
[self.view addSubview:tempView.view];
}
In SecondViewController.m file
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(#"received info %#", [self.fullName description]);
self.nameLabel.text = [self.fullName description];
}
In log i am getting (name :) value but in secondViewController received info is null.
I am doing this all by using xib file. No use of Storyboard.
Please help me to get this form data to secondViewController.
Thanks.
Sorry , I couldn't get why you have done these two line code :
tempView.fullName = self.nameTextField.text;
[tempView setFullName:self.fullName];
Instead ,
Make a property of NSString in Second View Controller's .h file
#property (nonatomic,retain) NSString *strFullName;
and synthesize in .m file.
#synthesize strFullName;
Now ,
-(IBAction)nextVCButton:(id)sender
{
SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
NSLog(#"name : %#",self.nameTextField.text);
tempView.strFullName = self.nameTextField.text;
[self.view addSubview:tempView.view];
}
I think you need to use Navigation controller if you want to navigate from one view controller to another view controller. well here you need to do property- synthesize the iVar "fullName" in ThirdViewController. and retain the value in SecondViewController .
1. ThirdViewController.h
#property(nonatomic, retain) NSString *fullName;
2. ThirdViewController.m
#synthisize fullName;
dealloc {
[fullName release];
}
3. SecondViewController.m
-(IBAction)nextVCButton:(id)sender
{
SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
NSLog(#"name : %#",self.nameTextField.text);
tempView.fullName = self.nameTextField.text;
[tempView setFullName:self.fullName];
[self.view addSubview:tempView.view];
}
try presentViewController method instead of addSubview....
-(IBAction)nextVCButton:(id)sender
{
SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
NSLog(#"name : %#",self.nameTextField.text);
tempView.strFullName = self.nameTextField.text;
[self.view addSubview:tempView.view];
[self presentViewController:tempView animated:YES completion:nil];
}
Ok first of all I have to say that I am a bit of a noob on the iOS field.
That said I will explain my problem further.
I am making an app in which the user gets a list of animals. When the user picks an animal from the list --> the second viewcontroller opens and the imageview there must be set to the selected animal + there is a description of the animal.
With this part of code in my ViewDidLoad of viewController2.m
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationItem setTitle:#"Animal"]; //here the title has to be set to the animal but I will try this later
// Do any additional setup after loading the view from its nib.
UIImage * cowImage = [UIImage imageNamed:#"cow.png"];
UIImage * horseImage = [UIImage imageNamed:#"horse.png"];
ViewController1 *viewController1 = [[ViewController1 alloc]init];
characterNumber = viewController1.pickedRow;
//set the uiimageview based on characternumber
switch (characterNumber) {
case 0:
foto.image = pukkelpopImage;
detailInfo.text = #"blabla";
[self.navigationItem setTitle:characterName];
break;
case 1:
foto.image = cactusImage;
break;
default:
break;
}
}
In my ViewController 1.m I have this method for when an item gets selected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
ViewController2 *ViewController22 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
[[self navigationController] pushViewController:ViewController22 animated:YES];
pickedRow = indexPath.row; //As you can see here I try to get which row was tapped
}
Where could the issue be?
Thank you for reading
You are allocating a new instance of viewController1 in viewController2, which is not related at all to the viewController1 instance pushing viewController2.
Try to declare a NSInteger property in viewController2 to store the picked row and set the value of viewController2 instance before you push it in didSelectRowAtIndexPath.
In ViewController2.h declare the property:
#property (nonatomic) NSInteger pickedRow;
In ViewController1.m didSelectRowAtIndexPath, set the property after you initialize the viewController2 instance, before you push it:
viewController2.pickedRow = indexPath.row;
No need to initialize the viewController1 in ViewController2.m:
// ViewController1 *viewController1 = [[ViewController1 alloc]init];
The variable characterNumber can be replaced with self.pickedRow.
I am using a UIButton, on clicking it I want to display the contents that are present in my NSMutableArray in UITableView with the help of UIPopOverController i.e. I want a UITableView to pop up whose cells show the contents of my NSMutableArray.
I am using the following lines of code:
UITableViewController *table= [[UITableViewController alloc]init];
table.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:table];
self.popoverController = popover;
popoverController.delegate = self;
NSString *hDir = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *hFilePath = [hisDir stringByAppendingPathComponent:#"hhhh.txt"];
NSArray *array = [NSArray arrayWithContentsOfFile:hFilePath ];
NSMutableArray *kkkk = [[NSMutableArray alloc] init];
for (NSDictionary *dict in array) {
[kkkk addObjectsFromArray:[dict allKeys]];
}
table = [[UIImageView alloc] initWithFrame:[window bounds]];
// Set up the image view and add it to the view but make it hidden
[window addSubview:table];
table.hidden = YES;
[window makeKeyAndVisible];
I am unable to get the UITableView to pop up on the press of my UIButton. Can anyone help me to sort it out?
One way to show the UITableView in the UIPopOverController is by creating a new UIViewController class. And invoking it in initWithContentViewController method of UIPopOverController.
1. Create a new UIViewController or UITableViewController class. Create an instance of it.
2. Use the instance in the initWithContentViewController method of UIPopOverController.
3. Mention from where it should "pop"
For Example in your Button action :
-(IBAction)yourButtonAction:(id)sender
{
YourNewViewController*newVC=[[YourNewViewController alloc]init];
UIPopoverController*somePopOver=[[UIPopoverController alloc]initWithContentViewController:catergoryVC]; //Tell which view controller should be shown
[somePopOver setPopoverContentSize:CGSizeMake(200, 200)]; // set content size of popover
[somePopOver presentPopoverFromRect:yourButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; //From where it should "pop"
}
It seems you want to present it from a UIBarButtonItem so instead of presentPopoverFromRect use presentPopoverFromBarButtonItem
[somePopOver presentPopoverFromBarButtonItem:yourBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
If you want to display popover on press of button click, then first add your button in viewcontroller, display that view controller as follows:
In app delegate write code:
MyViewController *viewController = [[MyViewController alloc] init];
[self.window addSubView:viewController.view];
In MyViewController add button and provide target to that button displayPopup as follows:
-(void)displayPopup:(id)sender
{
UITableViewController *tblViewPopover = [[UITableViewController alloc] init];
tblViewPopover.tableView.delegate = self;
tblViewPopover.tableView.dataSource = self;
tblViewPopover.tableView.backgroundColor = [UIColor whiteColor];
tblViewPopover.tableView.separatorStyle= UITableViewCellSeparatorStyleSingleLine;
float theWidth = 280;
tblViewPopover.contentSizeForViewInPopover = CGSizeMake(theWidth,200);
if(m_popOvrController){
[m_popOvrController dismissPopoverAnimated:NO];
[m_popOvrController release];
m_popOvrController=nil;
}
m_popOvrController = [[UIPopoverController alloc] initWithContentViewController:tblViewPopover];
[tblViewPopover release];
[m_popOvrController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
and you can use tableview delegate methods to display data in tableview.
I think, UIPopoverViewController is initialized using UIViewController and here you are using UIView(UITableView).
Can you please try using UITableViewController instead?
Also, if things does not work according to plan when you create it using the code try using an XIB explicitely.
This should help.
hi everyone i am new to iphone development.
Actually i am trying with some sample app where i have a textField in the Viewcontroller and a Button,when i enter a string in the textfield and press the button it should display the same string in NextView.so can anyone help me out in doing this.
i worked with transition between one view to another view,but i need copy string from Viewcontroller1 to NextView
#ViewController1
-(IBAction)next
{
NextView *Nview = [[NextView alloc]initWithNibName:#"NextView" bundle:nil];
[self.view addSubview:Nview.view];
}
Set an ivar in your NextView called "newString" for example, then pass a string to that ivar form your first controller.
For Example, not tested (and this is one of many ways you can do this):
FirstView
NextView * next = [[NextView alloc] initWithNewString: myTextField.text];
[self.navigationController presentModalViewController: next animated: YES];
NextView
#synthesize newString
-(id)initWithNewString:(NSString*)someString
{
newString = someString;
return self;
}
Then throughout your NextView, just call upon newString wherever you want to get the value of the previous views textField.
-(IBAction)next
{
NextView *Nview = [[NextView alloc]initWithNibName:#"NextView" bundle:nil];
Nview.string_Object=string_to_copy;//declare string_Object in NextView.h
[self.view addSubview:Nview.view];
}
Try this:
In your first view while naviagting:
NextView *nav = [[NextView alloc] init];
nav.textFieldValue = textField.text;
[self.navigationController pushViewController:nav animated:YES];
And in your NextView's .h file create a property:
#property(nonatomic, retain) NSString *textFieldValue;
And in .m file synthesize it like:
#synthesize textFieldValue;
Now you can use textFieldValue in NextView class
P.S: Don't forget to release it :)
As you are a beginner, this will be a good guidance for you to understand the exact flow and it will make you learn how to pass values from one class to another.
Here is an approach (haven't tested, but should work)
Give your textField a tag value like
textField.tag = 1;
and in NextView access it like
UITextField *parentViewTextField = (UITextField*)[self.superview viewWithTag:1]
In my project , On clicking the button the string present in the button Action method should store in popover table view cell.
I cam able to store a single sting , to the first cell ....
And now my problem is i had Four buttons each button action consists of 4 strings , and now the should at a time to the popover table view ,,,
#import "SecondDetailViewController.h"
-(IBAction)viewButtonPressed:(id)sender
{
[super viewDidUnload];
//create the view controller from nib
self.tablePopoverController = [[[TablePopoverController alloc]
initWithNibName:#"TablePopover"
bundle:[NSBundle mainBundle]] autorelease];
////-------------------------------
myArray = [[NSMutableArray alloc] initinitWithObjects:myString,myString2,myString3,myString4,myString5,myString6,nil];
tablePopoverController.getingOrder = myArray ;
NSLog(#"table popo %#",myArray);
tablePopoverController.contentSizeForViewInPopover = CGSizeMake(250, 250);
//create a popover controller
self.popoverController = [[[UIPopoverController alloc]
initWithContentViewController:tablePopoverController] autorelease];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(IBAction)orderButtonPressed
{
myString = staterlable1.text;
[myArray addObject:myString];
NSLog(#"myArray%#",myString);
}
-(IBAction)orderButton2Pressed
{
myString2 = staterlable2.text;
NSLog(#"myArray%#",myString2);
[myArray addObject:myString2];
}
-(IBAction)orderButton3Pressed
{
myString3 = staterlable3.text;
[myArray addObject:myString3];
NSLog(#"myArray%#",myString3);
}
-(IBAction)orderButton4Pressed
{
myString4 = staterlable4.text;
[myArray addObject:myString4];
NSLog(#"myArray%#",myString4);
}
-(IBAction)orderButton5Pressed
{
myString5 = staterlable5.text;
[myArray addObject:myString5];
NSLog(#"myArray%#",myString5);
}
-(IBAction)orderButton6Pressed
{
myString6 = staterlable6.text;
[myArray addObject:myString6];
NSLog(#"myArray%#",myString6);
my Problem Is after clicking these buttons the myString1 - to - myString6 NSString objects Should Store into NSMutableArray so That i will display all the strings in the TableViewPopOverController which will popover when clicking the another button in the second detailViewController........
thanks in Advance......
The usual way to do this is to embed TablePopoverController in a UINavigationController. Then, in TablePopoverController when handling tableView:tableView didSelectRowAtIndexPath:indexPath push detailViewController into the UINavigationController.
For example, you could build Controller structure the following way (based on your example):
//create a popover controller
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:[[[UINavigationController alloc] initWithRootViewController:initWithContentViewController:tablePopoverController] autorelease]] autorelease];
It is similar to your popover-creation code, put inserts a UINavigationController under the popover. Now, in TablePopoverController you should handle row selections the usual way with a UINavigationController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetaiViewController *detail = [[DetaiViewController alloc] init];
/* Configure detail using indexpath here indexPath
...
*/
[self.navigationController pushViewController:detail animated:YES];
}
This will work as expected (by pushing the new view into the UINavigationController) because we set controller structure with a UINavigationController.