iOS - Connect UITableViewCell to another ViewController Programmatically - objective-c

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];

Related

Push a string and display in a UITextField

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];
}

Custom NSView for NSTableView not updating components

I created a custom NSView for a NSTableView.
I am trying to fill the fields I created in it using the Interface Builder but I can't. I would say each component is properly linked and the code is OK.
This is the function
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
Account *account = (Account *)[self.dataSource objectAtIndex:row];
AccountTableCellViewController *controller = [[AccountTableCellViewController alloc] init];
controller.subtitleLabel.stringValue = account.name;
[controller.titleLabel setStringValue:account.num];
NSLog(#"%#", controller.titleLabel);
return [controller view];
}
And here is the picture of the bindings:
The table shows all the rows correctly, but is not filling the NSTextFields as expected.
UPDATE:
This is how it looks like (not updating views):
Any suggestion?
The labels haven't been loaded from the nib yet. I'd just create an extra account instance variable in your view controller, assign it there, then load the information in -(void)awakeFromNib

Transition to a view in table with dynamic cells

I create tableview and I fill the table dynamic data.
How to create transition between cell and another view.
Сells are filled with the names of files in the folder documents.
I use storyboard.
App for iPad.
You can make transition from cell to another view using following code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
anotherView *obj =[[anotherView alloc]initWithNibName:#"anotherView" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
}
this method is a delegate method of tableview and when you will select any cell ,it will be called and will go to another view

How to load a table from a .nib when an item in a previous table is selected?

At the moment, I have an iOS app that starts out with a NavigationView (root view) and a table contained in the root view below the navigation bar. I am attempting to load another view (hoping to make it another table) from a .nib file when the first row in the original table is selected. How can I do this?
Any help or advice would be appreciated. Thank you very much.
You need to make use of the UITableViewDelegate method, tableView:didSelectRowAtIndexPath:
Ensure that your tableview's delegate is set to your view controller inside Interface Builder, or if you are not using interface builder..
[tableView setDelegate:self];
Your view controller will then adopt the UITableViewDelegate protocol and respond to tableView:didSelectRowAtIndexPath: when a row is selected.
Loading your new view when the first row is selected will be implemented like so..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0){ // the first row
MyView *myView = [[MyView alloc] init];
[self.navigationController pushViewController:myView animated:YES];
[myView release];
}
}

My table view does not navigate to another uiview page. What might be wrong?

My table view cells have the ContentView as the Labels. When I click on them to navigate to another view whose viewController is as shown does not navigate.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailedWebViewController *detailedWebViewTab1=[[DetailedWebViewController alloc] initWithNibName:#"DetailedRssWebView" bundle:Nil];
[self.navigationController pushViewController:detailedWebViewTab1 animated:NO];
[detailedWebViewTab1 release];
}
on tap it stays where it is highlighting the table in blue.
the object for the XIB is being created but cannot navigate to it.
Try to check in debugger if your detailedWebViewTab1 is really not nil. It seems to be so according to your description.