0
嗨,我這裏有一個問題,傳遞網址方法
我能夠獲得「imageName」變量中的URL字符串存儲成功在showImage方法。
我需要做同樣的方法「segmentedControlIndexChanged」,但我不能得到變量「imageName」。
無論如何,我可以聲明IBAction方法的工作方式與showImage方法類似嗎?
我試過 - >「-(IBAction) segmentedControlIndexChanged:(NSString *)imageName{}
」但它不能工作,我無法獲得變量「imageName」。
- (void) showImage:(NSString *)imageName
{
NSData *imageData;
//NSString * string1 = [NSString stringWithFormat:imageName];
imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageName]];
//NSLog(@"%@",imageName);
image = [[UIImage alloc] initWithData:imageData];
self.imageView.image = image;
[imageView setFrame:CGRectMake(5, 10, image.size.width, image.size.height)];
[scrollview setScrollEnabled:YES];
if(image.size.height+20 >= 224)
{
[scrollview setContentSize:CGSizeMake(289, image.size.height + 20)];
}
else {
[scrollview setContentSize:CGSizeMake(289, 224)];
}
}
////////
-(IBAction) segmentedControlIndexChanged{
switch (self.segmentedControl.selectedSegmentIndex) {
case 0:
image = [UIImage imageNamed:image1name];
self.imageView.image = image;
[imageView setFrame:CGRectMake(5, 10, image.size.width, image.size.height)];
[scrollview setScrollEnabled:YES];
if(image.size.height+20 >= 224)
{
[scrollview setContentSize:CGSizeMake(289, image.size.height + 20)];
}
else {
[scrollview setContentSize:CGSizeMake(289, 224)];
}
break;
case 1:
image = [UIImage imageNamed:image2name];
self.imageView.image = image;
[imageView setFrame:CGRectMake(5, 10, image.size.width, image.size.height)];
[scrollview setScrollEnabled:YES];
[scrollview setContentSize:CGSizeMake(289, image.size.height+20)];
break;
case 2:
image = [UIImage imageNamed:image3name];
self.imageView.image = image;
[imageView setFrame:CGRectMake(5, 10, image.size.width, image.size.height+1)];
[scrollview setScrollEnabled:YES];
[scrollview setContentSize:CGSizeMake(289, image.size.height+20)];
break;
default:
break;
}
}
編輯
我所遇到的錯誤訪問錯誤,任何人都知道這是什麼意思或任何人可以告訴我一些方法來解決呢?
所以,如果我有18個按鈕調用同樣的方法,我需要18例? – robobooga 2011-01-26 03:01:27