Push a string and display in a UITextField - objective-c

I am doing a small app and I am using a UISplitVIewController and I am trying to push the UITable cell text to the detail view and display it in a UITextField. I have managed to push the string nicely when i test it with a NSLog but when i apply to the UITextField it does not display not sure why here my method: (I am doing this using a storyboard)
-(void)pushModuleName:(NSString*)moduleName
{
self.Lv4ModuleTitleTextField.text = moduleName;
NSLog(#"name pushed%#",moduleName);
}
Not sure why this doesn't work.
[UPDATE]
UITableViewController.m (where the method is called)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedModule = [NSString stringWithFormat:#"%#",[_numberOfRows objectAtIndex:indexPath.row]];
Lv4GradeViewController *lv4 = [[Lv4GradeViewController alloc] initWithNibName:nil bundle:nil];
[lv4 pushModuleName:selectedModule];
}

You are creating a new instance of Lv4GradeViewController with the following code but no XIB file which will contain the text field:
Lv4GradeViewController *lv4 = [[Lv4GradeViewController alloc] initWithNibName:nil bundle:nil];
I would suggest you instantiate Lv4GradeViewController with the storyboard instantiateViewControllerWithIdentifier method:
Lv4GradeViewController *lv4 = [self.storyboard instantiateViewControllerWithIdentifier:#"IdentifierName"];
And remember to set the storyboard ID of the Lv4GradeViewController the same as IdentifierName in the storyboard.

The problem is that you're not getting a reference to the Lv4GradeViewController that you have on screen, you're creating a new one with alloc init. A split view controller, has a viewControllers array, with the controller at index 0 being the master controller, and the one at index 1 being the detail controller. So, the didSelectRowAtIndexPath method should look like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedModule = [NSString stringWithFormat:#"%#",[_numberOfRows objectAtIndex:indexPath.row]];
Lv4GradeViewController *lv4 = self.splitViewController.viewControllers[1];
[lv4 pushModuleName:selectedModule];
}

Related

Switch to another ViewController by selecting Cell of programmatically created collectionView

I've got a CollectionView which was programmatically created, now I want to switch to another CollectionView by selecting one of its Cells. Heres my code so far, but nothing happens:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
NSLog(#"Cell selected");
DetailCell *detailCell = [[DetailCell alloc] init];
[self.navigationController pushViewController:detailCell animated:YES];
}
Console says "Cell selected", so the CollectionView recognizes my touch, but the app won't switch to the other view. I've created a ViewController with the custom Class "DetailCell".
I'd check and make sure your self.navigationController isn't nil.
I just solved this problem :
mainView .m
cView = [[CollectionView alloc]init];
cView.view.frame = CGRectMake(0, 0, 320, 436);
cView.nav = self.navigationController;
[_contentScrollView addSubview:cView.view];
CollectionView.h
#property (nonatomic,weak) UINavigationController *nav;
CollectionView.m
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
DetailCell *detailCell = [[DetailCell alloc] initWithDetails:_pageCategorie and: indexPath];
[_nav pushViewController:detailCell animated:YES];
}

iOS - Connect UITableViewCell to another ViewController Programmatically

I have programmatically created a tableView populated it with some rows. However, I was wondering upon tapping one of these cells how could I navigate to another view controller while passing data to the other viewController as well?
This is what I filled each cell with:
cell.textLabel.text = [NSString stringWithFormat:#"#%#", currentAccount.username];
How do I pass currentAccount.username to another viewController I just created? I am not using storyboards as I had created the UITableView programmatically. However, I have created another view controller called FeedViewController.
In your table view delegate method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
you would instantiate your FeedViewController, pass any data to it using its properties and then display it.
Something like:
FeedViewController* feedVC = [[FeedViewController alloc] init];
feedVC.username = currentAccount.username
[self presentViewController:feedVC animated:YES completion:nil];

Unrecognized selector sent to instance when creating cell

I'm trying to reuse cell created in my storyboard,
I'm using this code:
MyTableView * mytableview;
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
mytableview = [sb instantiateViewControllerWithIdentifier:#"myTable"];
AlertCell *cell;
cell = [mytableview.tableView dequeueReusableCellWithIdentifier:#"alertCell"];
cell.message.text = #"some text";
return cell;
I get this error:
[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0xe02b7d0
this line eventually generates the error:
[mytableview.tableView dequeueReusableCellWithIdentifier:#"alertCell"];
The table view when using the cell is programaticlly created.
Everything i wanted works! but i got the errors in the log anyway
Thanks a lot!
You cannot create the table view when the cell is created.
You have to create the table view in a method that i called when the view controller is created, such as viewDidLoad.
Then in the cell method use the tableView pointer that is included in the method.
Also, the error actually indicates a problem with your datasource as well.
There are so many apparent knowledge gaps, maybe the best way is to read through the Table View Programming Guide.
I didn't exactly understand when you are creating table. You should not instantiate at the same time. Why you needed to call this line?
mytableview = [sb instantiateViewControllerWithIdentifier:#"myTable"];
If you want to use tableview, just create it normally and add it to your viewcontroller instead of using above line of code in viewDidLoad.
UITableView *tableView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain];
tableView.rowHeight = 45;
[self.view addSubview:tableView];
tableView.delegate = self;
tableView.datasource = self;
Implement tableview's data source and delegate methods. And in cellForRowAtIndexPath::
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"newFriendCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"newFriendCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
//do your stuff
return cell;
}

how to display popover click on a tableview cell in ipad

i am using a TableView in my application where i want a Pop over View when i clicked on a tabel cell, all the content which is in table Cell should display in a pop over view so plz suggest me how to do??
i have some sample code below which is not working..so suggest with code i want all the content in the cell to displayed in the pop over view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView *aView = [[UIView alloc] init];
UIPopoverController *popoverController = [[UIPopoverController alloc]
initWithContentViewController:aView];
popoverController.popoverContentSize = CGSizeMake(320, 416);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[popoverController presentPopoverFromRect:cell.bounds inView:cell.contentView
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
The UIPopoverController class reference clearly states
To display a popover, create an instance of this class and present it
using one of the appropriate methods. When initializing an instance of
this class, you must provide the view controller that provides the
content for the popover. Popovers normally derive their size from the
view controller they present
Your popoverController should have a view controller and not a view.
YourViewController *aViewController = [[YourViewController alloc] initWithNibName:nibName bundle:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc]
initWithContentViewController:aViewController];
Then you can present this pop over
Your code is fine, but
You should have UIViewController instead UIView.
you have to pass the view controller instead of view

iPad: SplitViewController with navigation

I'm following Apple sample code "MultipleDetailViews" but what I want to do is that:
at start, shows the RootViewController (table view) display the default detailViewController (1st detailView)
when user selected a table cell, push into the stack, display the SubCategoriesVC (table view) in the master of the splitView but don't update the detailView.
in SubCategoriesVC, selecting a table cell.. update the detailViewController (2nd detailView)
So, in RootViewController.m, I push another navigation
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SubCatVC *browseSubCatView = [[SubCatVC alloc] initWithNibName:#"SubCatVC" bundle:nil];
[self.navigationController pushViewController:browseSubCatView animated:YES];
[browseSubCatView release];
}
Then, in SubCatVC.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
SecondDetailViewController *newDetailViewController = [[SecondDetailViewController alloc] initWithNibName:#"SecondDetailViewController" bundle:nil];
detailViewController = newDetailViewController;
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
self.splitViewController.viewControllers = viewControllers;
[viewControllers release];
// Dismiss the popover if it's present.
if (self.popoverController != nil) {
[self.popoverController dismissPopoverAnimated:YES];
}
// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (self.rootPopoverButtonItem != nil) {
[detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}
[detailViewController release];
[[NSNotificationCenter defaultCenter] postNotificationName:#"updateProduct" object:nil];
}
but it didn't update my detailView.. so I don't know what's wrong?
Src here: http://pastebin.com/iy6SqLqt
Hope someone can advise me. Thanks
I Have not looked at your source, but but a common problem with Split views are delegates.
When you Push a new rootController ont the nav stack, you need to make sure it has the pointer to the detailViewController that you want it to talk to. You can check htis my logging the delegate before you try to update it:
In your SubCatVC (or any root for that matter):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//do stuff, init alloc vc's....
NSLog(#"DELEGATE: %#",self.delegate);
//push/delegate etc..
}
If you find its nil, copy the original roots delegate, or when your putting your new detail in, notify/set the root you want to comunicate with it.
If you need any more detail, just ask.