How to pass data to detail view after being selected in a table view?

The userNamelbl isn't instantiated until the view is loaded from the nib file. This doesn't happen immediately at initialisation, but will have happened by the time viewDidLoad is called So, you should to declare a property in DetailView to store your title, and then assign that value to userNamelbl. Text in the viewDidLoad method For example, in your table viewController: DetailView *detailVC = DetailView alloc initWithNibName:nil bundle:nil; detailVC.

UserName = userList objectAtIndex: indexPath. Row and in your detail viewController: (void) viewDidLoad { super viewDidLoad; detailVC.userNameLbl. Text = self.

UserName; } The viewController's navigationItem property is created when the viewController is initialised, hence you can assign to the navigationItem. Title immediately.

The userNamelbl isn't instantiated until the view is loaded from the nib file. This doesn't happen immediately at initialisation, but will have happened by the time viewDidLoad is called. So, you should to declare a property in DetailView to store your title, and then assign that value to userNamelbl.

Text in the viewDidLoad method. For example, in your table viewController: DetailView *detailVC = DetailView alloc initWithNibName:nil bundle:nil; detailVC. UserName = userList objectAtIndex: indexPath.

Row; and in your detail viewController: - (void) viewDidLoad { super viewDidLoad; detailVC.userNameLbl. Text = self. UserName; } The viewController's navigationItem property is created when the viewController is initialised, hence you can assign to the navigationItem.

Title immediately.

Also, you can consider having a User class and passing an instance of it to your view. Then your view can initialize any parts of itself that are specific to the user. It may even help to make this User class be a Core Data entity type.

– George Sep 26 at 23:00 Doing this has caused a warning for an NSString and UILabel mismatch on types - is there a way to implement your solution and avoid this? – tarheel Sep 26 at 23:14 I assumed that userList is an array of NSStrings. If the userName property is also be an NSString, you shouldn't get a mismatch – Ashley Mills Sep 27 at 9:01.

If so, I'd say the 'correct' approach would be to create a custom init method that passed in the data you required. For example: DetailView alloc initWithTitle:(NSString *)title text:(NSString *)text There's nothing inherently wrong with your approach, but passing the data the view controller requires at its creation is architecturally better (in my opinion, I'm sure someone will disagree!). For example, think of a table view controller - you pass in the table view style in the init method, you don't set it later on.

Same for a UIImageView - you have an initWithImage method that lets you set the image at creation.

Conceptually, I definitely agree with your approach, but I am gonna need a little more help(im a noob) on the implementation. My understanding is that the above line would go inside of my didSelectRowAtIndexPath: method in the TableView, and then(this is where I get fuzzy) the actual implementation of the initWithTitle:text: method be in the DetailView. Right?

– tarheel Sep 26 at 23:18 +1 for this approach. I would recommend this over the other approaches mentioned simply because of its simplicity and elegance. – Bourne Sep 26 at 23:38 @lxt I would love to see more on this solution, but I had to give the credit to AshleyMills because that is the solution I went with in my app.

Thanks Everyone! – tarheel Sep 27 at 2:46.

You should have a DetailViewController class that inherits from UIViewController or some sublcass (like UITableViewController); it will have DetailViewController. M and DetailViewController. H files to declare and define your class.

It should have a corresponding nib that defines the UIView that the UIViewController loads; it will have a DetailView. Xib file. You can't assign the value to the UILabel directly because UIView hasn't been loaded at the time you need to assign the user name value.

In order to do what you want, you should declare a public property (userName) to "push" the value onto the detail view controller from the master controller. Once the detail view is loaded, it can assign the value from the property to the label and nav bar.In your master view controller (UITableViewController): - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { tableView deselectRowAtIndexPath:indexPath animated:NO; DetailViewController *detailVC = DetailView alloc initWithNibName:@"DetailView" bundle:nil; detailVC. UserName = userList objectAtIndex:indexPath.

Row; self. NavigationController pushViewController:detailVC animated:YES; detailVC release; } In your detail view controller: DetailViewController. H @property (retain) NSString* userName; @property (nonatomic, retain) IBOutlet UILabel *userNameLbl; DetailViewController.

M @synthesize userName; @synthesize userNameLbl; -(void) viewDidLoad { super viewDidLoad; self.userNameLbl. Text = self. UserName; self.navigationItem.

Title = self. UserName; }.

When a cell in the table view is selected I segue to a UIView. Within the UIView I want to display the details of the catObj that was selected in the table view. NSLog(@"%@ is the selected object.",selectedObject.

NSLog(@"preparing segue with %@...", selectedObject. Text = selection. Text = selection.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions