问题描述
我想使用在点击UITableCellView之后收到的值.我将值存储到数组中,并定义了UITableCellView的ViewController的实例,以便到达这些数组.即使我可以从另一个ViewController到达数组,结果也总是将"0"写入要获取数据的文本字段.我需要存储在数组中的确切数据.这是我尝试执行的代码;
I want to use the value that I received after tapping a UITableCellView. I stored the value into arrays, and defined the instance of the ViewController of UITableCellView in order to reach those arrays. Even though I can reach the arrays from the other ViewController, it always write "0" as a result to the textfield I want to have the data. I need the exact data stored in the array. Here is the code how I tried to do it;
(fourthViewController)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *msg = [[NSString alloc] initWithFormat:
@"%@ rate for %@ has been selected",
[rates objectAtIndex:[indexPath row]],
[countries objectAtIndex:[indexPath row]]];
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:@"New country selected"
message:msg
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
fCountry = [countries objectAtIndex:indexPath.row];
fRate = [rates objectAtIndex:indexPath.row];
}
我正在尝试使用数组的FirstViewController;
The FirstViewController I'm trying to use the arrays;
@interface FirstViewController : UIViewController{
@public
...
FourthViewController *fourthViewController;
}
...
@property (nonatomic, assign) FourthViewController *fourthViewController;
@synthesize fourthViewController;
提前感谢您的回答!
推荐答案
您将整个ViewController声明为一个属性.只需将数组用作属性即可.
You are declaring the whole ViewController as a property. Just use your arrays as properties.
通常,传递数据非常有用: http://www.theappcodeblog.com/2011/04/15/passing-data-between-views-tutorial-using-a-protocol-在您的iPhone应用程序中进行委托/
Generally, there is a great tut for passing data: http://www.theappcodeblog.com/2011/04/15/passing-data-between-views-tutorial-using-a-protocol-delegate-in-your-iphone-app/
这篇关于使用来自另一个ViewController的ViewContoller变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!