小编Hex*_*ark的帖子

ABS(A)和abs(int)

我对这两个在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

c macros xcode function objective-c

5
推荐指数
2
解决办法
7847
查看次数

带视图控制器的Xcode和alertview

我想要实现的是在单击我的警报视图按钮时转到另一个视图.我的警报视图在我的loadingView中,这个警报视图是从另一个名为classA的类中调用的.

这就是它在classA中的调用方式.

[LoadingViewController showError];
Run Code Online (Sandbox Code Playgroud)

这是在loadingView类中加载View的方法.

+ (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)

这给了我一个错误.'应用程序试图在其自身上呈现模态视图控制器.呈现控制器是UINavigationController:..

注意:我的方法是'+'

xcode viewcontroller alertview

1
推荐指数
1
解决办法
3996
查看次数

代理不存在,EXC_BAD_ACCESS

我有一个TableViewController,它在运行时,创建另一个类的实例并用它调用json,例如.

TableViewController;

-(void)viewDidLoad{
JSONClass *jc = [[JSONClass alloc]init];
jc.JSONClassDelegate = (id)self;
[jc view];
}
Run Code Online (Sandbox Code Playgroud)

JSONClass将继续从Web检索数据,一旦完成,将向tableViewController发送委托方法调用"JSONClassDataReceived".如,

JSONClass;

-(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)

TableViewController;

- (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)

json objective-c ios

1
推荐指数
1
解决办法
2040
查看次数

标签 统计

objective-c ×2

xcode ×2

alertview ×1

c ×1

function ×1

ios ×1

json ×1

macros ×1

viewcontroller ×1