当我尝试发布字典时,我得到一个例外.
这是我的代码:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (!tableDataDictionary)
{
DebugLog(@"initializing tableDataDictionary");
tableDataDictionary = [ [NSMutableDictionary alloc] init];
}
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[mainTableView deselectRowAtIndexPath: [mainTableView indexPathForSelectedRow] animated:NO];
[tableDataDictionary release];
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我有以下代码:
#define checkLiteMessage \
{ \
#ifdef LITE_VERSION \
if (alertView.tag == 100) \
{ \
if (buttonIndex == 1) \
[ [UIApplication sharedApplication] openURL: buyAppLink]; \
[alertView release]; \
return; \
} \
#endif \
} \
Run Code Online (Sandbox Code Playgroud)
我想要做的是每次调用checkLiteMessage时都要包含以下代码:
#ifdef LITE_VERSION
if (alertView.tag == 100)
{
if (buttonIndex == 1)
[ [UIApplication sharedApplication] openURL: buyAppLink];
[alertView release];
return;
}
#endif
Run Code Online (Sandbox Code Playgroud)
我的问题是什么?为什么这段代码不能编译?
谢谢.
我有一个结构,并在其中指向2D数组.但是当我尝试将一个实际的2D数组分配给该指针时,我没有成功 - 编译器说我的指针是指向一维数组的指针.
这是我的代码:
typedef GLfloat Vertex2f[2];
typedef GLfloat TextureCoordinate[2];
typedef struct {
GLuint texture_name; // OpenGL ID of texture used for this sprite
Vertex2f *vertices; // array of vertices
TextureCoordinate *texture_coords; // texture vertices to match
GLubyte *vertex_indices;
} game_sprite;
void loadState()
{
game_sprite ballSprite;
createAndLoadTexture("ball.png", &ballSprite.texture_name);
const Vertex2f tempVerticesArray[4] = {
{-100.0f, -100.0f},
{-100.0f, 100.0f},
{100.0f, 100.0f},
{100.0f, -100.0f}
};
ballSprite.vertices = &tempVerticesArray; //The problem appears to be here
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它工作?
谢谢.
我有一个小问题.当从objective-c函数传递给c函数时,我有一个数组并且它的大小发生了变化.
void test(game_touch *tempTouches)
{
printf("sizeof(array): %d", sizeof(tempTouches) );
}
-(void)touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event
{
game_touch tempTouches[ [touches count] ];
int i = 0;
for (UITouch *touch in touches)
{
tempTouches[i].tapCount = [touch tapCount];
tempTouches[i].touchLocation[0] = (GLfloat)[touch locationInView: self].x;
tempTouches[i].touchLocation[1] = (GLfloat)[touch locationInView: self].y;
i++;
}
printf("sizeof(array): %d", sizeof(tempTouches) );
test(tempTouches);
}
Run Code Online (Sandbox Code Playgroud)
控制台日志是:
[touchesEnded] sizeof(array): 12
[test] sizeof(array): 4
Run Code Online (Sandbox Code Playgroud)
为什么两种方法的大小不同?
在[test]方法中,返回大小始终为4,而不依赖于数组的原始大小.
谢谢.