I’ve thoroughly looked for a solution and have not found one. It seems really elementary what I’m trying to do, however all the webpages which I have read so far do not address them.
I have a two sets of the 3 usual files.
- MyTableViewController.h .m .xib
- TableViewDetails.h .m .xib
When the user clicks on a row on the MyTableViewController.xib, it displays TableViewDetails.xib with the contents of an array, declared/populated in MyTableViewController.
- For Demo sake I want to call the array (tableDataList) by passing the number row of the item, the code which think can implement this is commented out
So how do I achieve this?
MyTableViewController.h
@interface MyTableViewController : UITableViewController {
NSMutableArray *tableDataList;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navCont;
@property (nonatomic, readwrite, retain) NSMutableArray *tableDataList;
//+ (NSString *)getTempArray:(int)number;
//- (NSString *) getTempArray_m: (int) number;
@end
MyTableViewController.m
//#import "MyTableViewController.h"
#import "TableViewDetailsView.h"
@implementation MyTableViewController
@synthesize tableDataList;
- (void)viewDidLoad
{
NSMutableArray *tempArray = [[[NSMutableArray alloc] initWithObjects:@"Item 1",@"Item 2",@"Item 3",@"Item 4",@"Item 5",@"Item 6", nil] autorelease];
tableDataList = [[NSMutableArray alloc] init];
tableDataList = tempArray;
}
//+ (NSString *)getTempArray:(int)number {
// return [MyTableViewController getTempArray_m: number];
//}
//
//- (NSString *)getTempArray_m:(int)number {
//
// return [self.tableDataList objectAtIndex:number];
//}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
NSLog(@"pushing...");
TableViewDetailsView *temp = [[[TableViewDetailsView alloc] initWithNibName:@"TableViewDetailsView"bundle:nil] autorelease];
// ...
// Pass the selected object to the new view controller.
[self.navCont pushViewController:temp animated:YES];
}
@end
MyTableViewController.h
#import <UIKit/UIKit.h>
//#import "MyTableViewController.h"
//@class MyTableViewController;
@interface TableViewDetailsView : UIViewController {
UIButton *buttonGetArray;
}
@end
TableViewDetailsView.m
#import "TableViewDetailsView.h"
//#import "MyTableViewController.h"
@implementation TableViewDetailsView
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// MyTableViewController *MyTableVC = [[MyTableViewController alloc] init]; - This is Wrong
// NSString *item = [MyTableViewController getTempArray:1];
// NSLog(@"The Array item: %@", item);
}
Last few words, could you please provide actual code alterations and not pad this questions off or provide a link to readings. I really want to learn but find that its not very helpful when (what seems like) simple questions aren’t addressed here.
By all means give me the relevant pointers to the information, but solve the problem here first so others in future may benefit greater.
Thank you for taking the time to read my question.
There are a few things to do here.
First, in
MyTableViewController.m
In
TableViewDetailsView.h
you should provide a public instance variable so you can set the details you want to display. Right now it is a string you want to display. Later it could be a custom model with data. One way to do it is to declare the @property. For example in TableViewDetailsView.h:
So you initalize your DetailViewController and set the data you want to display right when the user taps the row. So in your “- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath” in MyTableViewController.m you do:
If you declare your myDetailString as an IBOutlet, you can link it with your .xib file and set it up in Interface Builder. Otherwise you would have to set it up in code, For example in your viewDidLoad method. The string to display is already set inside the other method (didSelectRowAtIndexPath)…
Hope that clears some things. Otherwise ask again.