虽然这是最常见的问题之一,但我找不到一个全面的答案.我需要在UITableView中有自定义单元格.一些包含标签或文本字段,一些包含图像和按钮.我为每种类型的细胞制作了单独的类.我正在使用具有多个部分的GroupStyle表.现在我在cellForIndexPath中添加单元格,其中section为switch-case,if-else为section中的行:
id cell;
switch(indexPath.section) {
case 0:
if(indexPath.row==0) {
CellA *cell = [[[CellA alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Celld%",indexPath.row]] autorelease];
//configure cell
return cell;
}
else if(indexPath.row==1) {
CellB *cell = [[[CellB alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Celld%",indexPath.row]] autorelease];
//configure cell
return cell;
}
break;
case 1:
if(indexPath.row==0) {
CellC *cell = [[[CellC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"Celld%",indexPath.row]] autorelease];
//configure cell
return cell;
}
break;
default:
break;
}
return cell;
Run Code Online (Sandbox Code Playgroud)
我也必须在最后返回单元格,因为由于代码块内部的单元格的定义,单元格变得无法识别.为了解决这个问题,我在顶部声明了id的单元格.但我知道这不是正确的方法.如何解决此声明和访问多种类型单元格的问题?
目前有4-5行适合一个屏幕而不需要滚动.所以,我不是在重复使用细胞.但是在编辑时会挤出更多行.在另一个表中,有更多行可以滚动屏幕.这意味着我必须重复使用细胞.所以,我的问题的第二部分是; 如何重用多个自定义单元格?
我知道Box2d世界中快速移动的物体会引起隧道效应并相互穿过.解决方案是将主体定义为子弹.我这样做但是身体有时仍然相互交叉,特别是如果遇到点不完全朝向中间并且身体在交叉时部分重叠.有解决方案吗
这就是我制作所有身体的方式:
redBall = [CCSprite spriteWithFile:@"red-ball" rect:CGRectMake(0, 0, 34, 34)];
redBall.tag = 1;
[self addChild:redBall];
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set((winSize.width/2)/PTM_RATIO, redBall.position.y/PTM_RATIO);
ballBodyDef.userData = redBall;
ballBodyDef.bullet = true;
_ballBody = _world->CreateBody(&ballBodyDef);
// Create circle shape
b2CircleShape circle;
circle.m_radius = 17.0/PTM_RATIO;
// Create shape definition and add to body
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = 0.2f;
ballShapeDef.friction = 0.0f;
ballShapeDef.restitution = 1.0f;
_ballFixture = _ballBody->CreateFixture(&ballShapeDef);
Run Code Online (Sandbox Code Playgroud)
我在TouchesEnd中将此球移动为:
- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch …Run Code Online (Sandbox Code Playgroud) 我想将Box2D添加到我的cocos2d 0.99.5 iphone/ipad项目中.我不想从模板开始新的Box2D项目.
我已将包含Collision,Common和Dynamics的Box2D文件夹添加到我的项目中,并复制了GLES-Render.h和.m以及许可证.我也把'.' 在项目信息中的"标题搜索路径"前面,并将AppDelegate.m更改为.mm.
当我编译它给我2543错误像"Box2D /碰撞/形状/ bCircleShape.h:没有这样的文件或目录"....请帮助为什么不是它找到Box2d包以及如何解决它.