I am a noob at iOS application development.
I trying to create "UITableView -> to Detail View" application.
And found out "Master-Detail Application" project in the project template.
Then I tried it out. Then the problem came. I had a dynamic table view, so I have to make the detail view look dynamic too. Like this :
Table View Detail View
Item A Item A is an <item_A_description>, with <item_A_summary>
Item B Item B is an <item_B_description>, with <item_B_summary>
Item C Item C is an <item_C_description>, with <item_C_summary>
the problem is, after I go back to the table (list) view using back button menu,
then I choose the again the item from different row of the list, then the Detail View doesn't changed to selected Item value.
I did pass the value using (MasterView) -> initWithNibName -> (DetailView)
My environment : XCode 4.2 for SnowLeopard, iOS SDK 5
Updated
After I check the log, the parameter value did passed with the correct value. But the IBOutlet of UIlabel that I set didn't change it's value.
This is my code :
MasterViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TheItems *a = [data objectAtIndex:[indexPath row]];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPhone" bundle:nil withItemId:(NSString *)a.itemId];
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
[self.detailViewController release];
}
}
DetailViewController.h :
@interface metapsDetailViewController : UIViewController <UISplitViewControllerDelegate>
{
NSString *itemId;
}
@property (strong, nonatomic) IBOutlet UILabel * detailItem;
@property (nonatomic, retain) NSString *itemId;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withItemId:(NSString *)itemId;
DetailViewController.m :
@synthesize detailItem = _detailItem;
@synthesize itemId;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withItemId:(NSString *)itemId
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Detail", @"Detail");
self.itemId = itemId;
}
}
- (void)viewDidLoad
{
self.detailItem.text = self.itemId;
}
Thanks
You only create the detailViewController when it doesn't exist. The Item you give to the detailViewController is in your init, so the item will only be set once. You should add a method (or property) to your detailViewController where you can set the item, so that it can change your detailViewController when you get new data.
Edit: Implement something like this:
@synthesize itemId = _itemId;
-(void)setitemId:(NSString*)itemId{
if(_itemId != itemId)
{
[_itemId release];
_itemId = [itemId retain];
self.detailItem.text = _itemId;
}
}