我有一个使用UIKit菜单的cocos2d动力游戏,所以我只将框架用于一个viewcontroller,这就是游戏本身.此外,它只有一个场景.由于cocos2d 2.0导演本身是一个UIViewController子类,所以MenuViewController当用户点击一个开始按钮时我就把它推进去:
-(void)startGameButtonPressed {
CCDirectorIOS* director = (CCDirectorIOS *) [CCDirector sharedDirector];
// Create an CCGLView with a RGB565 color buffer, and a depth buffer of 0-bits
self.glView = [CCGLView viewWithFrame:CGRectMake(0, 0, 480, 320)
pixelFormat:kEAGLColorFormatRGB565 //kEAGLColorFormatRGBA8
depthFormat:0 //GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
// attach the openglView to the director
[director setView:glView];
[director runWithScene:[GameLayer scene]];
[director setDelegate:(id <CCDirectorDelegate>) [[UIApplication sharedApplication] delegate]];
[self.navigationController pushViewController:director animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
当用户启动第一个游戏时,第一次调用该方法时,这样可以正常工作.比赛结束后,我打电话[[CCDirector sharedDirector] end].
大多数导演设置都是在appDelegate中完成的(它与默认的Cocos2d模板保持不变).我只将CCGLView保留属性作为我的保留属性MenuViewController,因为否则应用程序在[[CCDirector sharedDirector] end] …
我想在UITableView的页脚中显示一个UIButton(对于标题应该完全相同).
这段代码在我的TableViewController的viewDidLoad中:
UIButton *footerShareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[footerShareButton setFrame:CGRectMake(10, 0, 70, 50)];
NSLog(@"%f", footerShareButton.frame.size.width);
[self.tableView setTableFooterView:footerShareButton];
NSLog(@"%f", footerShareButton.frame.size.width);
NSLog(@"%f", self.tableView.tableFooterView.frame.size.width);
Run Code Online (Sandbox Code Playgroud)
但是,此代码不起作用.Button的宽度太大,它是320.(虽然高度正确.)第一个NSLog输出70,第二个和第三个输出320.所以看起来setTableFooterView方法奇怪地调整了按钮的大小.
我已经将UIButton放在另一个UIView中,然后将其设置为表格页脚,从而解决了这个问题:
UIButton *footerShareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[footerShareButton setFrame:CGRectMake(10, 0, 70, 50)];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 70, 50)];
[aView addSubview:footerShareButton];
[self.tableView setTableFooterView:aView];
[aView release];
Run Code Online (Sandbox Code Playgroud)
这样做,按钮具有正确的宽度.
但是,我不明白为什么第一个代码示例不起作用.谁能解释一下?
我有一个存储可比数据的通用java类:
public class MyGenericStorage<T extends Comparable<T>> {
private T value;
public MyGenericStorage(T value) {
this.value = value;
}
//... methods that use T.compareTo()
}
Run Code Online (Sandbox Code Playgroud)
我还有一个名为Person的抽象类:
public abstract class Person implements Comparable<Person>
Run Code Online (Sandbox Code Playgroud)
和两个具体的子类,教授和学生:
public class Professor extends Person
public class Student extends Person
Run Code Online (Sandbox Code Playgroud)
现在当我想像这样创建一个MyGenericStorage时,我收到一个错误:
//error: type argument Student is not within bounds of type-variable T
MyGenericStorage<Student> studStore = new MyGenericStorage<Student>(new Student());
//this works:
MyGenericStorage<Person> persStore = new MyGenericStorage<Person>(new Student());
Run Code Online (Sandbox Code Playgroud)
我认为这是因为我对理解泛型存在根本问题.有人可以向我解释这个,还有,如何修复它?
编辑:
我已将MyGenericStorage更改为以下内容:
public class MyGenericStorage<T extends Comparable<? super T>>
Run Code Online (Sandbox Code Playgroud)
现在它似乎工作.有人可以解释原因吗?
我有一个标准的UITableView.我想shadowColor将单元格设置textLabel为[UIColor whiteColor],但仅在触摸单元格时.为此,我使用以下代码.它是一个自定义的UITableViewCell子类,它覆盖setSelected/setHighlighted:
@implementation ExampleTableViewCell
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
[self setShadowColorSelected:selected];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:animated];
[self setShadowColorSelected:highlighted];
}
- (void)setShadowColorSelected:(BOOL)selected {
if (selected) {
self.textLabel.shadowColor = [UIColor blackColor];
}else {
self.textLabel.shadowColor = [UIColor whiteColor];
}
}
@end
Run Code Online (Sandbox Code Playgroud)
我对这种方法的问题是,在取消选择时,单元格的标签文本和阴影都是白色的周期非常短.请参阅此屏幕截图,该截图是在取消选择的确切时刻拍摄的:

它与这两个帖子的方法基本相同:
我在后一个问题中使用了接受答案的方法.
我创建了一个非常简单的代码项目并将其上传到github.它显示了我的问题.它只是一个显示单个单元格的UITableViewController.
除此之外,没什么特别的.UITableView委托方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if …Run Code Online (Sandbox Code Playgroud) 我正在为 iOS 开发一个动态框架。这个框架使用了一个静态库,它集成了CocoaPods:
+--MyDynamicFramework
+--PublicHeader1.h
+--PublicHeader2.h
+--Sources
+--Pods
+--StaticLib
+--PublicHeader3.h
+--StaticLib.a
Run Code Online (Sandbox Code Playgroud)
现在,我在我的动态框架的源代码中使用PublicHeader3.h(它是 的一部分StaticLib),但我也想将它公开为我正在构建的动态框架的公共标头。因此,使用我的动态框架的应用程序应该能够看到所有三个公共标头。这是可能的,如果是,如何?
我有一个自定义的UIViewController子类,它被推送到UINavigationController堆栈上.我想在初始化/推送时添加一些我自己的数据.我是不是该
a)用我的数据作为参数写一个自定义的init方法,像这样?
MyCustomViewControllerSubclass.m:
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle myCustomData:(NSData *)data{
if(self = [super initWithNibName:nibName bundle:nibName]){
//do stuff with my data
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
或者b)在我的viewcontroller中添加一个属性来存储我的自定义数据,然后在初始化后添加它?
在这些方法之一中是否存在一些优势/劣势,还是有另一种方法可以做到这一点?
回复非常高兴!
我有一个MKAnnotation名为的对象数组arrAnnotations.我想从与CLLocation名为"newLocation" 的对象中存储的坐标相同的坐标中选择一个注释.
我正在尝试使用a NSPredicate,但它不起作用.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF.coordinate == %f)", newLocation.coordinate];
NSArray* filteredArray = [arrAnnotations filteredArrayUsingPredicate:predicate];
[self.mapView selectAnnotation:[filteredArray objectAtIndex:0] animated:YES];
Run Code Online (Sandbox Code Playgroud)
filteredArray始终包含零个对象.
我也试过以下,但也无效
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate == %f)", newLocation.coordinate];
Run Code Online (Sandbox Code Playgroud)
和
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate > 0)"];
Run Code Online (Sandbox Code Playgroud)
和
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(coordinate.latitude == %f)", newLocation.coordinate.latitude];
Run Code Online (Sandbox Code Playgroud)
最后两个崩溃了应用程序,第三个崩溃了NSInvalidArgumentExceptionfor [NSConcreteValue compare:]和第四个,因为latitude它不符合键值编码(我认为这是因为坐标只是一个c-struct而不是一个NSObject?).
我该如何使用它NSPredicate?任何人都可以给我一个链接到一个文件,显示Predicates如何在幕后工作?我不明白他们实际做了什么,尽管我已阅读并理解Apple的Predicate Programming Guide的大部分内容.正在使用for ... in构造中搜索带有谓词的大型数组比使用谓词循环更有效吗?如果是/否,为什么?
iphone ×4
ios ×3
uitableview ×2
cocoa ×1
cocoapods ×1
comparable ×1
comparison ×1
footer ×1
generics ×1
header ×1
init ×1
ipad ×1
java ×1
nspredicate ×1
objective-c ×1
performance ×1
predicate ×1
xcode ×1