我对这两个在xcode,ABS(A)和abs(int)中的区别感到困惑.似乎也无法在网上找到任何解释.我应该使用哪个?我实际上在研究加速度计.使用ABS(A)和abs(int)给出了两个不同的值.使用abs(int)有时会产生一个inf值,而ABS(A)会给我一个不同的值,但从不给inf.谢谢!
http://www.switchonthecode.com/tutorials/iphone-tutorial-reading-the-accelerometer
我想要实现的是在单击我的警报视图按钮时转到另一个视图.我的警报视图在我的loadingView中,这个警报视图是从另一个名为classA的类中调用的.
[LoadingViewController showError];
Run Code Online (Sandbox Code Playgroud)
+ (void)showDestinationError{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Error"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
alert.tag = DEST_ERR;
[alert show];
}
Run Code Online (Sandbox Code Playgroud)
+ (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag = DEST_ERR){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
UINavigationController *secondView = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
secondView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[secondView presentModalViewController:secondView animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个TableViewController,它在运行时,创建另一个类的实例并用它调用json,例如.
-(void)viewDidLoad{
JSONClass *jc = [[JSONClass alloc]init];
jc.JSONClassDelegate = (id)self;
[jc view];
}
Run Code Online (Sandbox Code Playgroud)
JSONClass将继续从Web检索数据,一旦完成,将向tableViewController发送委托方法调用"JSONClassDataReceived".如,
-(void)viewDidLoad{
//codes of URL connection goes here...
NSMutableURLRequest *request = [[NSMutableURLRequest new];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:responseData waitUntilDone:YES];
}
- (void)fetchedData:(NSData *)responseData {
NSMutableDictionary *data = [NSJSONSerialization
JSONObjectWithData:responseData
options:NSJSONReadingMutableContainers
error:&error];
if (JSONPromotionsLocationsDelegate && [JSONPromotionsLocationsDelegate respondsToSelector:@selector(JSONPromotionsLocationsDataReceived)]) {
[JSONPromotionsLocationsDelegate JSONPromotionsLocationsDataReceived];
}
}
Run Code Online (Sandbox Code Playgroud)
- (void)JSONClassDataReceived{
[tableView reloadTable];
}
Run Code Online (Sandbox Code Playgroud)
之后填充相关数据.
在我的tableViewController上调用委托方法JSONClassDataReceived之前,如何在TableViewController上按下后退按钮时如何停止JSONClass?
我试过了
jc.JSONClassDelegate = nil;
jc = nil;
Run Code Online (Sandbox Code Playgroud)
当按下后退按钮时,我的应用程序崩溃,因为JSONClass已达到JSONClassDelegate,因此无法找到方法 - (void)JSONClassDataReceived,因为tableViewController视图不再存在.我也尝试过在JSONClass中实现dealloc.似乎没有工作.
- …
Run Code Online (Sandbox Code Playgroud)