我试图使用rhomobile框架让iphone的指南针工作.我已经完成了rhomobile部分,创建了一个在iphone上调用本机方法的工作包装器,但是我无法让事件发挥作用.
Locationmanager.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface locationController : NSObject <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property (strong, nonatomic) CLLocationManager *locationManager;
- (id)init;
- (void)dealloc;
@end
Run Code Online (Sandbox Code Playgroud)
Locationmanager.m
#import "Locationmanager.h"
#include "ruby/ext/rho/rhoruby.h"
//store the values
double gx, gy, gz, gth;
//init location
locationController *lc;
@implementation locationController
@synthesize locationManager;
- (id)init {
if (self = [super init]) {
self.locationManager = [[CLLocationManager alloc] init];
NSLog(@"%@", [CLLocationManager headingAvailable]? @"\n\nHeading available!\n" : @"\n\nNo heading..\n");
NSLog(@"%@", [CLLocationManager locationServicesEnabled]? @"\n\nLocation available!\n" : @"\n\nNo location..\n");
// check if the …Run Code Online (Sandbox Code Playgroud) 好吧,我知道这个错误主要来自发送方法调用或尝试访问已经解除分配的变量.
这是问题所在:
.h
@interface TimeEntry : NSObject <NSCopying, NSCoding> {
NSDate *from;
NSDate *to;
NSString *information;
}
@property (nonatomic, retain) NSDate *from;
@property (nonatomic, retain) NSDate *to;
@property (nonatomic, copy) NSString *information;
@end
Run Code Online (Sandbox Code Playgroud)
而且我的班级是dealloc.
-(void)dealloc{
[super dealloc];
[to release];
[from release];
[information release];
}
Run Code Online (Sandbox Code Playgroud)
当我收到EXC_BAD_ACCESS错误时,这是追溯的事情

所以我正在向已经解除分配的对象发送消息?
所以我打开NSZombie,这停止了我的崩溃.它并没有像我希望的那样给我一些可爱的崩溃报告.相反,它只是让程序崩溃.
在上面的dealloc方法中,如果我注释掉[发布]和[从发布]应用程序不会崩溃.如果我只注释其中一个......它不会崩溃.在调试窗口中往返有不同的内存地址.
记忆管理怎么这么难!!!!
有人提出任何线索吗?
谢谢,
担
谈论的是Objective-c中的类和对象.我无法理解[super dealloc]的概念.我们有一些类说myClass,它继承自NSObject.它有一些方法,并从父类继承其他方法.所以我们这里也有dealloc方法.为什么我不能只使用[myInstance dealloc]?我是否认为我们调用父类方法来杀死类的实例?为什么这么复杂?
这不是关于[myInstance发布]的讨论我对这个概念没问题.
关于xcode中的超级含义,我有一个小问题.例如,我有以下代码.如果我在dealloc方法中首先说[super dealloc]会有用吗?或者应该超级总是最后?什么是超级 - 我知道它的超级课程,但是它是父类还是?
这是此类的.h文件
@interface TwitterTableViewController : PullRefreshTableViewController<TweetDelegate>
Run Code Online (Sandbox Code Playgroud)
这是上面接口的.m类的一些代码
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[self.twitterManager release];
[tweets release];
[lastRefreshedLabel release];
[super dealloc];
Run Code Online (Sandbox Code Playgroud)
}
我已经检查了所有并且还没有令人满意的知识.如果任何人都可以用外行来解释这一点,那将是最好的.谢谢
我有一个实例变量被定义并合成为一个属性,如下所示:
@interface CardFrontView : GenericCardView {
UIImage *_letterImage;
}
@property (nonatomic, retain) UIImage *letterImage;
@end
@implementation CardFrontView
@synthesize letterImage = _letterImage;
...
Run Code Online (Sandbox Code Playgroud)
我将该letterImage属性设置为-init:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self != nil) {
NSString *filename = [[NSBundle mainBundle] pathForResource:@"fehu" ofType:@"png"];
self.letterImage = [UIImage imageWithContentsOfFile:filename];
} return self;
}
Run Code Online (Sandbox Code Playgroud)
然后,我发布它-dealloc,然后应用程序崩溃(EXC_BAD_ACCESS):
- (void)dealloc {
[super dealloc];
[_letterImage release];
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚应用程序崩溃的原因.有没有人知道这笔交易是什么?
我有一个类,在.h文件中定义了一个属性:
@property (retain) NSString *fontName;
Run Code Online (Sandbox Code Playgroud)
在.m文件中,我释放了属性:
-(void)dealloc {
[super dealloc];
[_fontName release];
}
Run Code Online (Sandbox Code Playgroud)
现在我偶尔会在[_fontName release]上收到EXC_BAD_ACCESS错误.这种情况非常罕见,我不确定如何调试它.发布@property(保留)是否正确?或者[超级dealloc]已经这样做了吗?
objective-c ×5
ios ×4
iphone ×4
cocoa-touch ×2
cocoa ×1
delegates ×1
ios4 ×1
retain ×1
rhomobile ×1