Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-20-2011, 07:21 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Default passing data from a TableView to a DetailView doesnīt work

Hey Guys,
i have a problem. i have a tableview which can be filled from a plist.

Code:
<dict>
	<key>besch</key>
	<string>level 1</string>
	<key>ItemChild</key>
	<array>
		<dict>
			<key>besch</key>
			<string>level 2</string>
			<key>ItemChild</key>
			<array>
				<dict>
					<key>besch</key>
					<string>level 3</string>
					<key>bildklein</key>
					<string>blume5_klein.jpg</string>
					<key>name</key>
					<string>Inside Inside Level 1</string>
				</dict>
			</array>
			<key>name</key>
			<string>INnside Level 1</string>
		</dict>
	</array>
	<key>name</key>
	<string>Level 1</string>
</dict>
</plist>

The data is loaded into an MutableArray.

Code:
interface View2Controller : UITableViewController {
	NSMutableArray* dataList1;   	
}
In die View2Controller in the cellForRowAtIndexPath i can use the data without a problem. Everything is going fine. The stings from the plist is shown where it should.

Code:
// Set up the cell...
	cell.textLabel.text = [[self.dataList1 objectAtIndex:indexPath.row] objectForKey: @"name"]; 	
    
    cell.detailTextLabel.text = [[self.dataList1 objectAtIndex:indexPath.row] 
                                 objectForKey:@"besch"];
now i have a detailview and want to fill some objects with the the same stuff and nothing happens...

i tried it like this:

Code:
_besch1Field.text = [dataList1 valueForKey:@"besch"];

_imageView.image = [UIImage imageNamed:[dataList1 valueForKey:@"bildklein"]];

i donīt know where the problem is. there is no crash, but nothing is shown in the detailsview;


HELP, i need somebody, HELP....
OldHank is offline   Reply With Quote
Old 03-20-2011, 08:14 AM   #2 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

How are you declaring datalist1?

Quote:
Originally Posted by OldHank View Post
Hey Guys,
i have a problem. i have a tableview which can be filled from a plist.

Code:
<dict>
	<key>besch</key>
	<string>level 1</string>
	<key>ItemChild</key>
	<array>
		<dict>
			<key>besch</key>
			<string>level 2</string>
			<key>ItemChild</key>
			<array>
				<dict>
					<key>besch</key>
					<string>level 3</string>
					<key>bildklein</key>
					<string>blume5_klein.jpg</string>
					<key>name</key>
					<string>Inside Inside Level 1</string>
				</dict>
			</array>
			<key>name</key>
			<string>INnside Level 1</string>
		</dict>
	</array>
	<key>name</key>
	<string>Level 1</string>
</dict>
</plist>

The data is loaded into an MutableArray.

Code:
interface View2Controller : UITableViewController {
	NSMutableArray* dataList1;   	
}
In die View2Controller in the cellForRowAtIndexPath i can use the data without a problem. Everything is going fine. The stings from the plist is shown where it should.

Code:
// Set up the cell...
	cell.textLabel.text = [[self.dataList1 objectAtIndex:indexPath.row] objectForKey: @"name"]; 	
    
    cell.detailTextLabel.text = [[self.dataList1 objectAtIndex:indexPath.row] 
                                 objectForKey:@"besch"];
now i have a detailview and want to fill some objects with the the same stuff and nothing happens...

i tried it like this:

Code:
_besch1Field.text = [dataList1 valueForKey:@"besch"];

_imageView.image = [UIImage imageNamed:[dataList1 valueForKey:@"bildklein"]];

i donīt know where the problem is. there is no crash, but nothing is shown in the detailsview;


HELP, i need somebody, HELP....
iSDK is offline   Reply With Quote
Old 03-20-2011, 08:21 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
How are you declaring datalist1?
i do it in the rootviewcontroller.m

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	NSString *path = [[NSBundle mainBundle] pathForResource:@"DataDetail1" ofType:@"plist"]; 
	NSMutableArray* tmpArray = [[NSMutableArray alloc] 
								initWithContentsOfFile:path]; 

	self.dataList1 = tmpArray; 
	[tmpArray release];
}
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
		
		
		View1Controller *view1Controller = [[View1Controller alloc] 
															initWithNibName:@"View2Controller" bundle:nil];
        
		view1Controller.dataList1 = [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"ItemChild"]; 

		[self.navigationController pushViewController:view1Controller animated:YES];
		[view1Controller release];
	}
everything work fine, until i want to read the content in the detailview
OldHank is offline   Reply With Quote
Old 03-20-2011, 08:41 AM   #4 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Ok, so if the problem is passing data then there must be a problem in this line:

Code:
view1Controller.dataList1 = [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"ItemChild"];
So try NSLog'ing
Code:
[[self.dataList1 objectAtIndex:indexPath.row] objectForKey:@"ItemChild"];
Quote:
Originally Posted by OldHank View Post
i do it in the rootviewcontroller.m

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	NSString *path = [[NSBundle mainBundle] pathForResource:@"DataDetail1" ofType:@"plist"]; 
	NSMutableArray* tmpArray = [[NSMutableArray alloc] 
								initWithContentsOfFile:path]; 

	self.dataList1 = tmpArray; 
	[tmpArray release];
}
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
		
		
		View1Controller *view1Controller = [[View1Controller alloc] 
															initWithNibName:@"View2Controller" bundle:nil];
        
		view1Controller.dataList1 = [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"ItemChild"]; 

		[self.navigationController pushViewController:view1Controller animated:YES];
		[view1Controller release];
	}
everything work fine, until i want to read the content in the detailview
iSDK is offline   Reply With Quote
Old 03-20-2011, 08:56 AM   #5 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
Ok, so if the problem is passing data then there must be a problem in this line:

Code:
view1Controller.dataList1 = [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"ItemChild"];
So try NSLog'ing
Code:
[[self.dataList1 objectAtIndex:indexPath.row] objectForKey:@"ItemChild"];

the data is passed perfectly... the problem is the show the data

Code:
_besch1Field.text = [dataList1 valueForKey:@"besch"];

_imageView.image = [UIImage imageNamed:[dataList1 valueForKey:@"bildklein"]];
is this the right way ?
OldHank is offline   Reply With Quote
Old 03-20-2011, 09:25 AM   #6 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Default

Yes, you were right...!!!!!

in the last viewcontroller, there is everything in the dataList1.

Code:
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // Navigation logic may go here -- for example, create and push another view controller.
    DetailViewController *detailViewController = [[DetailViewController alloc] 
                                                  initWithNibName:@"DetailViewController" bundle:nil];
   detailViewController.dataList1 = [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"ItemChild"]; ///Grabs relevant dictionary from array///

    
    
  //  detailViewController.drink = [self.dataList1 objectAtIndex:indexPath.row];

    
    [self.navigationController pushViewController:detailViewController animated:YES];
    
   

    
    [detailViewController release];

 //   detailViewController.title = [NSString stringWithFormat:@"X@", [dataList1 objectAtIndex:row];
                              
 detailViewController.title =  [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"besch"];

     NSLog(@"%@", dataList1);
        
}

Attaching to process 1977.
Pending breakpoint 1 - ""DetailViewController.m":40" resolved
Pending breakpoint 2 - ""View2Controller.m":77" resolved
2011-03-20 15:22:26.038 tableviews[1977:207] (
{
besch = "level 3";
bildklein = "blume5_klein.jpg";
name = "Inside Inside Level 1";
}
)


but thereīs nothing inside in the detailview controller... i didnīt change anything and push the data the same way from the viewcontroller to the detailviewcontroller as a did to push the data from one viewcontroller to another...
OldHank is offline   Reply With Quote
Old 03-20-2011, 09:40 AM   #7 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Question

yes, there is something wrong with the plist structure...

Code:
 detailViewController.dataList1 = [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"ItemChild"]; ///Grabs relevant dictionary from array///
something is wrong when i want to push the content of the itemchild to the detailview..


i donīt get it whats wrong....
OldHank is offline   Reply With Quote
Old 03-20-2011, 09:40 AM   #8 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Are you allocating the dataList1 in your detailViewController?

Quote:
Originally Posted by OldHank View Post
Yes, you were right...!!!!!

in the last viewcontroller, there is everything in the dataList1.

Code:
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // Navigation logic may go here -- for example, create and push another view controller.
    DetailViewController *detailViewController = [[DetailViewController alloc] 
                                                  initWithNibName:@"DetailViewController" bundle:nil];
   detailViewController.dataList1 = [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"ItemChild"]; ///Grabs relevant dictionary from array///

    
    
  //  detailViewController.drink = [self.dataList1 objectAtIndex:indexPath.row];

    
    [self.navigationController pushViewController:detailViewController animated:YES];
    
   

    
    [detailViewController release];

 //   detailViewController.title = [NSString stringWithFormat:@"X@", [dataList1 objectAtIndex:row];
                              
 detailViewController.title =  [[self.dataList1 objectAtIndex:indexPath.row]objectForKey:@"besch"];

     NSLog(@"%@", dataList1);
        
}

Attaching to process 1977.
Pending breakpoint 1 - ""DetailViewController.m":40" resolved
Pending breakpoint 2 - ""View2Controller.m":77" resolved
2011-03-20 15:22:26.038 tableviews[1977:207] (
{
besch = "level 3";
bildklein = "blume5_klein.jpg";
name = "Inside Inside Level 1";
}
)


but thereīs nothing inside in the detailview controller... i didnīt change anything and push the data the same way from the viewcontroller to the detailviewcontroller as a did to push the data from one viewcontroller to another...
iSDK is offline   Reply With Quote
Old 03-20-2011, 10:07 AM   #9 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
Are you allocating the dataList1 in your detailViewController?
Yes, i think so,

Code:
#import <UIKit/UIKit.h>


@interface DetailViewController : UIViewController <UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
  
    NSMutableArray* dataList1;   //allows data to be displayed in the Tableview in the form of an ARRAY// 

    IBOutlet UITextView *besch1Field;
    IBOutlet UITextView *besch2Field;
    IBOutlet UILabel *txtlabel;
    IBOutlet UIImageView *_imageView;
    
    
   


    
}

@property (nonatomic, retain) NSMutableArray* dataList1;
@property (nonatomic, retain) IBOutlet UITextView *besch1Field;
@property (nonatomic, retain) IBOutlet UITextView *besch2Field;
@property( nonatomic, retain) IBOutlet UILabel *txtlabel;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;



@end


Code:
#import "DetailViewController.h"
#import <UIKit/UIKit.h>
#import "RootViewController.h"
#import "View2Controller.h"
#import "Constants.h"
#import "tableviewsAppDelegate.h"


@implementation DetailViewController
@synthesize dataList1;
@synthesize besch1Field = _besch1Field;
@synthesize besch2Field = _besch2Field;
@synthesize txtlabel = _txtlabel;
@synthesize imageView = _imageView;



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}







- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    
    NSLog(@"%@", dataList1);
    
 
    
    _besch2Field.text = @"ins 2te feld";
 
      _besch1Field.text = [self.dataList1 valueForKey:@"besch"];

    
   
   _imageView.image = [UIImage imageNamed:[dataList1 valueForKey:@"bildklein"]];
    
    
    _txtlabel.text = @"statisch in ein label";
    
    _txtlabel.textColor = [UIColor blueColor];  

    
    
        
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    self.besch1Field = nil;
    self.besch2Field = nil;
    self.txtlabel = nil;
    self.imageView = nil;
    
    [super viewDidUnload];
 
}





- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)dealloc
{
    [_besch1Field release];
	_besch1Field = nil;
    
    [_besch2Field release];
	_besch2Field = nil;
    // [_txtlabel = release];
    _txtlabel = nil;
    [_imageView release];
	_imageView = nil;
    
    
    [dataList1 release];
    [super dealloc];
}



@end
OldHank is offline   Reply With Quote
Old 03-20-2011, 11:56 AM   #10 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

Change datalist1 to a NSDictionary. You have lines like
Code:
[self.dataList1 valueForKey:@"besch"]
which are NSDictionary methods
__________________

Last edited by iisword; 03-20-2011 at 11:59 AM.
iisword is offline   Reply With Quote
Old 03-20-2011, 12:54 PM   #11 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Default

Quote:
Originally Posted by iisword View Post
Change datalist1 to a NSDictionary. You have lines like
Code:
[self.dataList1 valueForKey:@"besch"]
which are NSDictionary methods
yes, i was trying this,
but i doesnīt work, because in the dataList1 is a undefined number of keys.

how can i convert the whole array to an nsdic without giving exact information about the content of the array...?
OldHank is offline   Reply With Quote
Old 03-20-2011, 01:52 PM   #12 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

Is the data in the dictionary from the user or the data from you?
__________________
iisword is offline   Reply With Quote
Old 03-20-2011, 02:43 PM   #13 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
OldHank is on a distinguished road
Default

Quote:
Originally Posted by iisword View Post
Is the data in the dictionary from the user or the data from you?
my data...
OldHank is offline   Reply With Quote
Old 03-20-2011, 03:47 PM   #14 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

Then you should know the keys, what's in them, and how the plist is made. There should be no reason for the number of keys to not be known.
__________________
iisword is offline   Reply With Quote
Reply

Bookmarks

Tags
detailview, plist, tableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 356
11 members and 345 guests
7twenty7, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, michelle, mistergreen2011, Sami Gh, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,661
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, tinamm64
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0