please check the picture you will more clear what I want to present
This is the first launch in First View
It's an empty table view
There is a add button on the right bar
If you press the Add button it will push to the Second View
The second is a only 3 rows table view
Tap the first row it will pop up a alert view to let you set a name
Press create ,the text will appear in the first row
<That's the question 1,I don't know how to pass the text to the cell...>
And keep forward ,That's a custom radio button in the row 2 and row 3
Unless You click the radio button first , otherwise you can't call this methord
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This is last two view Icon View 1
Icon View 2There are many buttons in the view,This the second question: If I press one of this button,it will return to the second view and show the button icon on the tableview row 2 or row 3
Finally,press the Done button(same on the right bar)
It will back to the First View and show what you type the name , and which icon you selected (Basis on radio button is selected)
That's the last question.
I upload my source code here:Link
You can download it ...
and here is the code about how I push the view...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row==0) {
[self nameInputAlertView];
}
RadioButtonClass *btn = [radioButtonArray objectAtIndex:[indexPath row]];
if (btn.selected) {
//Radio Button is selected ,use that icon
if (indexPath.row == 1) {
IconViewOne *iconViewOne = [[IconViewOne alloc]init];
iconViewOne.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:iconViewOne animated:YES];
[iconViewOne release];
}
if (indexPath.row==2) {
IconViewTwo *iconViewTwo = [[IconViewTwo alloc]init];
iconViewTwo.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:iconViewTwo animated:YES];
[iconViewTwo release];
}
}
}
so...Summary all the question...
1.How to write a text via textfield in the alert view to table view cell ?
2.How to selected an icon from last view to second view ?
3.Send all this two elements to First view : Name & Icon
I only know how to pass elements from view 1 to view 2... Don't know how to ret开发者_运维百科urn back......
Thanks mate , please help me to figure out this problem.I will very very appreciate !
BTW:you can take the radio button class to add in your any project
I dont know this is the correct way or not but i think this may help you. Since you want to retrieve the name and image in both views declare them in the appdelegate so that it can be accessed globally.
Que 1:
When selecting a row didSelectRow Delegate will be called. In that you will get the IndexPath. Store that indexPath globally. Then
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if ([alertView tag]==1) {
if (buttonIndex == 1){
NSLog(@"Created");
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:tableIndexPath]; //tableIndexpath is declared globally as NSindexpath
ReturnToFirstViewAppDelegate *appObj=(ReturnToFirstViewAppDelegate *)[[UIApplication sharedApplication]delegate];
appObj.selectedName = macroNameSetting.text; //Setting the Name globally
cell.detailTextLabel.text =macroNameSetting.text;
[self.tableView reloadInputViews];
}
}
}
Que 2 and 3
In the AppDelegate declare
NSString *selectedName;
UIImage *selectedImage;
Assign property and synthesize them
In your iconViews
- (void)setIcon : (id)sender{
UIButton *button = (UIButton *)sender;
UIImage *selectedImg = [UIImage imageNamed:[NSString stringWithFormat:@"marco%d",button.tag]];
ReturnToFirstViewAppDelegate *appObj=(ReturnToFirstViewAppDelegate *)[[UIApplication sharedApplication]delegate];
appObj.selectedImage = selectedImg;
// push your viewcontroller
}
In any Viewcontroller access them as
ReturnToFirstViewAppDelegate *appObj=(ReturnToFirstViewAppDelegate *)[[UIApplication sharedApplication]delegate];
//For example
//cell.image = appObj.selectedImage;
In any case if you dont like using AppDelegate Variables , there is one other method which You can use in case of Navigation Controllers :-
for eg. in "IConViewOne.m"
UITableViewCell* cell = [[[self.navigationController.viewControllers objectAtIndex:1] tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]] ;
cell.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"marco%d.png",button.tag]];
and then in "ViewWillAppear" of SecondView :-
[self.tableView reloadData];
Similarly for passing to RootViewController u can give:-
self.navigationController.topViewController.tableView
OR
[[self.navigationController.viewControllers objectAtIndex:0]tableView]
A great way to pass information from one object to another, without knowing who the recipient is (and there may be multiple objects interested in the information), is to post an NSNotification. It allows you to completely avoid direct knowledge of other objects.
Read Apple's document Notification Programming Topics and give it a try.
精彩评论