ฉันยังใหม่มากกับการเขียนโปรแกรมและวัตถุประสงค์ c ดังนั้นโปรดทำกับฉันง่ายๆ
ฉันต้องการ UIButton (ซึ่งฉันใช้เป็น IBAction) เพื่อเปลี่ยนรูปภาพใน UIImageView เมื่อกด ฉันใส่ UIImageView ลงใน UIScrollView ในกระดานเรื่องราว แต่ฉันหวังว่าฉันจะยังสามารถเปลี่ยนรูปภาพโดยทางโปรแกรมได้
ฉันค้นหาคำตอบทุกที่ทุกแห่งมาเป็นเวลาหลายชั่วโมง แต่ก็ไม่มีอะไรได้ผลสำหรับฉันเช่นกันเพราะมันไม่ใช่วิธีแก้ปัญหาที่ถูกต้องหรือฉันไม่ได้ทำอย่างถูกต้อง
ฉันได้ลองใช้รหัสนี้แล้วและรหัสอื่น ๆ แต่พวกเขามักจะส่งคืน "เธรด 1: สัญญาณ SIGABRT" เมื่อฉันกดปุ่ม:
imageView.image = [UIImage imageNamed: @"Ruler pic inch.png"];
นี่คือรหัสของฉันจนถึงตอนนี้:
ViewController.h
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface ViewController : UIViewController <ADBannerViewDelegate, UIScrollViewDelegate> {
ADBannerView *adView;
BOOL bannerIsVisible;
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *imageView;
IBOutlet UIButton *proVersion;
IBOutlet UIButton *howToUse;
}
- (IBAction)switchUnit:(id)sender;
@property (nonatomic, assign) BOOL bannerIsVisible;
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize bannerIsVisible;
@synthesize scrollView;
@synthesize imageView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Hide status bar:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
// iAd:
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50.0f);
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;
// Setting scrollview content size to size of image
scrollView.contentSize = CGSizeMake(320,2246);
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible) {
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 50.0f);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible) {
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50.0f);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)switchUnit:(id)sender {
// CODE THAT MAKES IMAGE CHANGE GOES HERE (I thought...)
}
@end
ความช่วยเหลือจะได้รับการชื่นชมอย่างมาก ฉันเบื่อกับมันแล้ว ฉันอาจจะทำผิดพลาดโง่ๆ ที่ไหนสักแห่งแต่ฉันก็ทำไม่ได้ ขอบคุณล่วงหน้า.