when i launch my app, on trying to do something, it will crash after a couple of seconds. I have warnings of warning: incorrect implementation of "downloadTextViewCOntroller. I also have "method definiton for -timerFinished not found and"method definiton for -timerFinished not found" this is my .m plese help me. the .h is also t the bottom
当我启动我的应用程序时,在尝试做某事时,它会在几秒钟后崩溃。我有警告警告:“downloadTextViewCntroller。我也有”的方法定义不正确 - 找不到-timerFinished的方法和“找不到-timerFinished的方法定义”这是我的.m请帮助我。 .h也是最底层的
//
// downloadTextViewController.m
// downloadText
//
// Created by Declan Scott on 18/03/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import "downloadTextViewController.h"
@implementation downloadTextViewController
@synthesize start;
-(IBAction)tapit {
start.hidden = YES;
}
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
if (fabsf(acceleration.x) > 2.0 || fabsf(acceleration.y) >2.0 || fabsf(acceleration.z) > 2.0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"This app was developed by Declan Scott and demonstrates NSURLConnection and NSMutableData"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (NSString *) saveFilePath
{
NSArray *pathArray =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"savedddata.plist"];
}
- (void)applicationWillTerminate:(UIApplication *)application {
NSArray *values = [[NSArray alloc] initWithObjects:textView.text,nil];
[values writeToFile:[self saveFilePath] atomically:YES];
[values release];
}
- (void)viewDidLoad {
UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.delegate = self;
accelerometer.updateInterval = 1.0f/60.0f;
NSString *myPath = [self saveFilePath];
NSLog(myPath);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
if (fileExists)
{
NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
textView.text = [values objectAtIndex:0];
[values release];
}
// notification
UIApplication *myApp = [UIApplication sharedApplication];
// add yourself to the dispatch table
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:myApp];
[super viewDidLoad];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (IBAction)fetchData {
loadingAlert = [[UIAlertView alloc] initWithTitle:@"Loading…\n\n\n\n" message:nil
delegate:self cancelButtonTitle:@"Cancel Timer" otherButtonTitles:nil];
[loadingAlert show];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 60.0f, 37.0f, 37.0f);
[loadingAlert addSubview:activityView];
[activityView startAnimating];
timer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(timerFinished) userInfo:nil repeats:NO];
NSURLRequest *downloadRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://simpsonatyapps.com/exampletext.txt"]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:1.0];
NSURLConnection *downloadConnection = [[NSURLConnection alloc] initWithRequest:downloadRequest delegate:self];
if (downloadConnection)
downloadedData = [[NSMutableData data] retain];
else {
// Error
}
}
- (void)connection:(NSURLConnection *)downloadConnection didReceiveData:(NSData *)data {
[downloadedData appendData:data];
NSString *file = [[NSString alloc] initWithData:downloadedData encoding:NSUTF8StringEncoding];
textView.text = file;
// get rid of alert
[loadingAlert dismissWithClickedButtonIndex:-1 animated:YES];
[loadingAlert release];
/// add badge
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}
@end
//
// downloadTextViewController.h
// downloadText
//
// Created by Declan Scott on 18/03/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface downloadTextViewController : UIViewController {
IBOutlet UITextView *textView;
NSMutableData *downloadedData;
UIAlertView *loadingAlert;
NSTimer *timer;
IBOutlet UIButton *start;
}
- (IBAction)fetchData;
- (IBAction)tapIt;
- (void)timerFinished;
@property (nonatomic, retain) UIButton *start;
@end
2 个解决方案
#1
2
You haven't implemented your -timerFinished
method declared in the header. In addition to declaring it in the header file, you need to provide the implementation of it, even if it's empty.
您尚未实现在标头中声明的-timerFinished方法。除了在头文件中声明它之外,您还需要提供它的实现,即使它是空的。
Your app is crashing because the timer fires after 10 seconds and it can't find the method it's trying to call.
您的应用程序崩溃,因为计时器在10秒后触发,但无法找到它尝试调用的方法。
#2
0
for one, you don't have anything for timerFinished, which is why you are getting that warning, but for now you can ignore it until you implement that in your code. And you fire a timer and have it do something it can't, because you don't have the code in place.
对于一个,你没有任何关于timerFinished的东西,这就是你得到那个警告的原因,但是现在你可以忽略它,直到你在代码中实现它。你启动一个计时器并让它做一些它不能做的事情,因为你没有准备好代码。
To fix it, just put the following in your .m
要修复它,只需将以下内容放在.m中即可
-(void)timerFinished
{
}
#1
2
You haven't implemented your -timerFinished
method declared in the header. In addition to declaring it in the header file, you need to provide the implementation of it, even if it's empty.
您尚未实现在标头中声明的-timerFinished方法。除了在头文件中声明它之外,您还需要提供它的实现,即使它是空的。
Your app is crashing because the timer fires after 10 seconds and it can't find the method it's trying to call.
您的应用程序崩溃,因为计时器在10秒后触发,但无法找到它尝试调用的方法。
#2
0
for one, you don't have anything for timerFinished, which is why you are getting that warning, but for now you can ignore it until you implement that in your code. And you fire a timer and have it do something it can't, because you don't have the code in place.
对于一个,你没有任何关于timerFinished的东西,这就是你得到那个警告的原因,但是现在你可以忽略它,直到你在代码中实现它。你启动一个计时器并让它做一些它不能做的事情,因为你没有准备好代码。
To fix it, just put the following in your .m
要修复它,只需将以下内容放在.m中即可
-(void)timerFinished
{
}