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

MynEz

macrumors newbie
Original poster
Jan 13, 2011
13
0
Regina,Sask
Hi, everyone

I'm now doing about editing data from image. My first page has many images so when the user choose one of those image, it is going to another view which consists about details. I used the Round Rect Button to display my image. My problem is when I choose one of those image the data always be the same as the first image. Here is my code;

If somebody can help me find out, please tell me

Thank you Sir!
Code:
// from appDelegate
	Character *bradpit = [[Character alloc] init];
	bradpit.cName = @"BradPitt"; 
	bradpit.cDescription = @"Good looking \nPositive \nCool";
	bradpit.cPicture = [UIImage imageNamed:@"bradpitt.png"];
	
	Character *angy = [[Character alloc] init];
	angy.cName = @"Angelina Jolie"; 
	angy.cDescription = @"Beautiful";
	angy.cPicture = [UIImage imageNamed:@"angy.png"];
	
	Character *arnold = [[Character alloc] init];
	arnold.cName = @"Arnold"; 
	arnold.cDescription = @"Muscle";
	arnold.cPicture = [UIImage imageNamed:@"arnold.png"];
	
	Character *bruce = [[Character alloc] init];
	arnold.cName = @"Bruce"; 
	arnold.cDescription = @"xkjx";
	arnold.cPicture = [UIImage imageNamed:@"Bruce.png"];
	
	self.characters = [[NSMutableArray alloc]initWithObjects:bradpit,angy,arnold,bruce,nil];
	[bradpit release];
	[angy release];
	[arnold release];
	[bruce release];
	
	[window addSubview:rootController.view];
	[window makeKeyAndVisible];

this is code for 1st page
Code:
- (void)viewDidLoad {
	self.title = @"First Page";
	UIBarButtonItem *moveButton = [[UIBarButtonItem alloc]initWithTitle:@"Setting" style:UIBarButtonItemStyleDone target:self action:@selector(setting)];
	self.navigationItem.rightBarButtonItem = moveButton;
	[moveButton release];
	BBAppDelegate *delegate = (BBAppDelegate *)[[UIApplication sharedApplication] delegate];
	character = delegate.characters;
    [super viewDidLoad];

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"];
	if(cell == nil){
		cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:@"cell"]autorelease];
		
	}
	Character *thisCharacter = [character objectAtIndex:indexPath.row]; 
	cell.textLabel.text = thisCharacter.cName;
	return cell;
}

}

and this is the last page
Code:
- (void)viewDidLoad {
	
	UIBarButtonItem *moveButton = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonItemStyleDone target:self action:@selector(edit)];
	self.navigationItem.rightBarButtonItem = moveButton;
	[moveButton release];
	
	BBAppDelegate *delegate = (BBAppDelegate *)[[UIApplication sharedApplication] delegate]; 
	Character *thisCharacter = [delegate.characters objectAtIndex:[index row]];
	self.title = thisCharacter.cName;
	descriptionView.text = thisCharacter.cDescription;
	descriptionView.editable = NO;
	pictureView.image = thisCharacter.cPicture;
	
    [super viewDidLoad];
}
 
Nope here is my last page
Code:
@implementation CharacterEdit
@synthesize index, pictureView, descriptionView, tableViews, data, listData,CurrentTitle,CurrentLevel, label;

- (id)initWithIndexPath:(NSIndexPath *)indexPath{
	if ( self == [super init] ) {
		index = indexPath;
	}
	return self;
}

- (void)viewDidLoad {
	
	NSString *Path = [[NSBundle mainBundle] bundlePath];
	NSString *DataPath = [Path stringByAppendingPathComponent:@"test.plist"];
	NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithContentsOfFile:DataPath];
	self.data = tempDict;
	[tempDict release];
	
		NSMutableArray *tempArray = [[NSArray alloc]init];
		self.listData = tempArray;
		[tempArray release];
				
		self.listData = [data objectForKey:@"Rows"];
		
	BBAppDelegate *delegate = (BBAppDelegate *)[[UIApplication sharedApplication] delegate]; 
	Character *thisCharacter = [delegate.characters objectAtIndex:index.row];
	descriptionView.text = thisCharacter.cDescription;
	self.title = @"Editing Profile";
	descriptionView.editable = NO;
	label.text = thisCharacter.cName;
	pictureView.image = thisCharacter.cPicture;
	
    [super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.listData count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
	NSMutableDictionary *dictionary = [self.listData objectAtIndex:indexPath.row];
	NSMutableArray *next = [dictionary objectForKey:@"Next"];
	
	if ([next count] == 0) {		
	}else {
		CharacterEdit *rvcontroller = [[CharacterEdit alloc]initWithNibName:@"CharacterEdit" bundle:[NSBundle mainBundle]];
		
		[self.navigationController pushViewController:rvcontroller animated:YES];
		rvcontroller.listData = next;
		[rvcontroller release];
	}
	
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
	if (cell == nil){
		cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier]autorelease];
		
	}
		
	NSDictionary *dictionary = [self.listData objectAtIndex:	indexPath.row];
	cell.textLabel.text = [dictionary objectForKey:@"Title"];
	cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
	
	
	
	return cell;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
	NSMutableDictionary *dictionary = [self.listData objectAtIndex:indexPath.row];
	NSMutableArray *next = [dictionary objectForKey:@"Next"];
	
	if ([next count] == 0) {		
	}else {
		CharacterEdit *rvcontroller = [[CharacterEdit alloc]initWithNibName:@"CharacterEdit" bundle:[NSBundle mainBundle]];
		
		[self.navigationController pushViewController:rvcontroller animated:YES];
		rvcontroller.listData = next;
		[rvcontroller release];
	}
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (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.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[index release];
	[pictureView release];
	[descriptionView release];
	[tableViews release];
	[data release];
	[listData release];
	[CurrentTitle release];
	[label release];
	
    [super dealloc];
}


@end
 
Where is the code where you push the last page onto the navigation stack? In particular do you create a new instance of the last page or use the same one every time? I ask as you set the index when it is created, not when you display it...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.