2010-11-29 46 views
1

请你就会更清楚,我想提出iphone:如何返回图像或从第二个视图到第一个视图的任何东西?

什么图片这是第一个视图首次发射

这是一个空表视图

有正确的酒吧

上添加按钮

alt text

如果按添加按钮,它会推动第二种观点

第二个是唯一的3行表视图

alt text

点击第一行会弹出一个警告视图让你设置一个名称

alt text

按创建时,文本将出现在第一行

< 这就是问题1,我不知道如何将文本传递给cel 1 ...>

并保持前进,这是在第2排和第3排

自定义单选按钮,只有点击单选按钮,第一,否则你不能把这个methord

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

这是最后两个视图 图标视图1 alt text 图标视图2 alt text

Ť这里有很多按钮在视图中,这第二个问题: 如果我按下这个按钮之一,它将返回到第二个视图,并显示在第二行或第三行上的按钮图标

最后,按完成按钮(右边栏上相同)

它会回到第一个视图,并显示你键入的名字,你选择哪个图标 (单选按钮基础被选中)

这是最后一个问题。

我在这里上传我的源代码:Link

你可以下载...

,这里是我如何推视图代码...

- (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]; 
     } 
    } 
} 

左右。 ..总结所有问题...

1.如何通过文本字段在警报视图中写入文本到表格视图单元格?

2.How从最后一个视图到第二视图中选择的图标?

3.Send所有这两个元素的第一视点:名称&图标

我只知道如何从图1的元素传递给视图2 ... 不知道如何返回回......

感谢队友,请帮我找出这个疑难问题会非常非常感激

BTW:你可以采取的单选按钮类在任何项目中添加

回答

1

我不知道这是正确的方式或不,但我认为这可能会帮助你。 由于您想要在两个视图中检索名称和图像,请在appdelegate中声明它们,以便全局访问它。

阙1:

当选择行didSelectRow代表将被调用。在那你将得到IndexPath。全局存储indexPath。然后

- (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]; 
    } 
    } 
} 

阙2和3

在AppDelegate中声明

NSString *selectedName; 
UIImage *selectedImage; 

指派属性和合成它们

在你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 
} 

在任何Viewcontro米勒访问他们作为

ReturnToFirstViewAppDelegate *appObj=(ReturnToFirstViewAppDelegate *)[[UIApplication sharedApplication]delegate]; 
//For example 
//cell.image = appObj.selectedImage; 
+0

谢谢!我现在正在看你的答案,我会尽快尝试。我为你的答案投票,看起来不错。 – 2010-11-30 02:33:44

+0

我声明NSString * selectedName;在AppDelegate.h中,但仍然有一个错误:请求成员“selectedName”在某些不是结构或联合? – 2010-11-30 03:12:25

+0

对不起,我忘记#import“Appdelegate.h” – 2010-11-30 04:05:31

1

在如果你不喜欢使用的AppDelegate变量任何情况下,还有另外一种方式,你可以在使用的情况下导航控制器的: -

为如。在 “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]]; 

,然后在SecondView的 “viewWillAppear中”: -

[self.tableView reloadData]; 

同样传递到RootViewController的u能给予: -

self.navigationController.topViewController.tableView 

OR

[[self.navigationController.viewControllers objectAtIndex:0]tableView] 
0

一个很好的方式来通过从一个对象到另一个对象的信息,而不知道接收者是谁(并且可能有多个对象对该信息感兴趣),就是发布一个NSNotification。它可以让你完全避免直接了解其他对象。

阅读苹果的文档Notification Programming Topics并试试看。

相关问题