Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dcastal1

macrumors newbie
Original poster
Oct 11, 2010
6
0
I am populating a UIScrollView from data collected via XML. I'd like the user to press a "Next" button on the view to be able to see more data relative to the data in the displayed view. When they click the button, a new view is presented, with the relevant data.
The problem I'm having is, whenever I try to pass the information from the initial element into the new view, all I get is the LAST element in the XML set. So, I need to be able to save the element set at the point of the button select, and pass that to the new view, however, I can't seem to figure it out.
Is what I'm trying to do possible?
The pertinent function is:
Code:
-(void)layoutScrollView
{
	CGRect workingFrame;
	
	workingFrame.origin.x = 0;
	workingFrame.origin.y = 0;
	workingFrame.size.width = 768;
	workingFrame.size.height = 1024;
	
	NoelsMyRealtorXMLView *myView;
	
	for(NoelsMyRealtorXMLElement *element in [self xmlElementObjects])
	{
		NSString *trimmedString = [[element title1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];		
		NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"NoelsMyRealtorXMLView" owner:nil options:nil];
		
		for(id currentObject in topLevelObjects)
		{
			if([currentObject isKindOfClass:[NoelsMyRealtorXMLView class]])
			{
				myView = (NoelsMyRealtorXMLView *)currentObject;
			}
		}		
		UIImage *t_Image_View = [[UIImage alloc]init];
		t_Image_View = [element imageView];
		tempImageView = t_Image_View;
		self.tempImageView = element.imageView;
		[[myView v_imageView]		setImage:[element imageView]];
		[[myView v_title1]			setText: [element title1]];
		[[myView v_photodate1]		setText: [element photodate1]];
		[[myView v_mls]				setText: [element MLS]];
		[myView						setFrame:workingFrame];
		
		
		UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
		btn.frame = CGRectMake(301, 636, 165, 30);
		[btn setTitle:@"See More Info" forState:UIControlStateNormal];
		[btn addTarget:self action:@selector(flipView:) forControlEvents:UIControlEventTouchUpInside];
		[btn setTag:1];
		btn.alpha = .5;
		currentMLS = [[NSMutableString alloc] initWithString:[element MLS]];
		[myView addSubview:btn];
		
		[scrollView addSubview:myView];
		
		workingFrame.origin.x = workingFrame.origin.x + 768; 
	}
	
	workingFrame.size.width = workingFrame.origin.x;
	[scrollView setContentSize:workingFrame.size];
	
	workingFrame.origin.x = 0;
	workingFrame.origin.y = 0;
	workingFrame.size.width = 768;
	workingFrame.size.height = 1024;
	
	[scrollView setFrame:workingFrame];
}
 
I'm not sure I understand what you mean. Do you mean a tableview instead of a scrollview?
 
OIC.
You're suggesting that instead of the view that I'm using, use a tableview. This would suggest I could pass along properties of the cell to the "Next" view? Forgive my newbie-ness...I'm pretty new to Objective-C, xcode and the entire platform.
I'm writing an app for a realtor. It has bunch of pictures of houses that I want to be able to scroll thru. Upon selecting the house, I want to display more detailed images of the house. So, scroll thru a high level set, then drill to a more detailed set.
 
Upon further consideration, you're wondering why I don't use a table view instead of a scroll view. No real reason I guess. ScrollView seemed like it was the straightforward way to do this. However, that may not be the case. Although, my understanding is that a table view will only allow vertical scrolling, and I'd prefer horizontal.
 
Here's the current iteration of flipview:
Code:
-(IBAction)flipView:(id)sender{
	WebViewController *webView = [[[WebViewController alloc] init] autorelease];
	[webView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

	if ([sender tag] == 1) {
		webView.webURL = currentMLS;
		webView.v_tempImageView = tempImageView;
	}else {
		webView.webURL = currentMapURL;
	}
	[self presentModalViewController:webView animated:YES];
}
 
Seems to me that your currentMLS instance variable is being set each time through your loop in layoutScrollView, so when your loop is done, it contains the last one. Instead you should look into setting it inside flipView: based on which button triggered the call.

Which brings me to: Also seems to me that your tag is not dynamic enough (i.e. you set it to 1 every time through your loop). You probably want to set this more dynamically and then have flipView: set currentMLS based on the tag.
 
Sweet! Thanks for the tip on the tag. I was initially planning on using that for something else, but changed my mind. However, I changed the design to store the elements from XML into an array, then use the tag to pass the index number of the array to the flipView function. That accessed the array data and passed that to the new view.
Thanks for your help and for not being hard on a newb.
 
Sweet! Thanks for the tip on the tag. I was initially planning on using that for something else, but changed my mind. However, I changed the design to store the elements from XML into an array, then use the tag to pass the index number of the array to the flipView function. That accessed the array data and passed that to the new view.
I like the way you think! :)

Thanks for your help and for not being hard on a newb.
You're welcome. Thank you for responding to my questions promptly and for having a grasp of the fundamentals, as well as treating those trying to help you with respect. It's appreciated.

I think you're gonna fit in fine here. :cool:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.