对于方法:
[NSThread detachNewThreadSelector:@selector(method:) toTarget:self withObject:(id)SELECTOR];
Run Code Online (Sandbox Code Playgroud)
如何传入@selector?我尝试将它转换为(id)以使其编译,但它在运行时崩溃.
更具体地说,我有一个像这样的方法:
+(void)method1:(SEL)selector{
[NSThread detachNewThreadSelector:@selector(method2:) toTarget:self withObject:selector];
}
Run Code Online (Sandbox Code Playgroud)
它崩溃了.如何在不崩溃的情况下传入选择器,以便新线程可以在线程准备好时调用选择器?
在使用xcode 6验证或提交我的应用时,我收到错误消息:
ERROR ITMS-9000: "Invalid Image Path - No image found at the path referenced
under key 'CFBundleIcons': 'AppIcon120x120'"
Run Code Online (Sandbox Code Playgroud)
我检查了我的plist文件,并且没有CFBundleIcons的条目.我正在使用资产目录,我可以看到它在常规目标设置下正确配置(它也可以使用设备上的图标正确构建).我也试过删除并重新添加目录.我最好的猜测是,当在多个目标中使用多个资产目录时,xcode中存在某种错误.有任何想法吗?
我使用的是AFNetworking和SDURLCache我所有的网络操作.
我这样SDURLCache设置:
SDURLCache *urlCache = [[SDURLCache alloc]
initWithMemoryCapacity:1024*1024*2 // 2MB mem cache
diskCapacity:1024*1024*15 // 15MB disk cache
diskPath:[SDURLCache defaultCachePath]];
[urlCache setMinCacheInterval:1];
[NSURLCache setSharedURLCache:urlCache];
Run Code Online (Sandbox Code Playgroud)
我的所有请求都使用cachePolicy NSURLRequestUseProtocolCachePolicy,根据apple docs的工作原理如下:
如果请求不存在NSCachedURLResponse,则从原始源获取数据.如果请求的缓存响应,则URL加载系统会检查响应以确定它是否指定必须重新验证内容.如果必须重新验证内容,则会与原始源建立连接以查看其是否已更改.如果它没有更改,则从本地缓存返回响应.如果已更改,则从原始源获取数据.
如果缓存的响应未指定必须重新验证内容,则检查响应中指定的最大期限或到期时间.如果缓存的响应足够新,则从本地缓存返回响应.如果确定响应是陈旧的,则检查原始源是否有更新的数据.如果有更新的数据,则从原始源获取数据,否则从缓存返回.
因此,只要缓存不是陈旧的,即使在飞行模式下一切都能正常工作.当缓存过期(max-age和其他)时,将调用失败块.
我一直在挖掘内部SDURLCache,这个方法返回一个有效数据的响应(我已经将数据解析为一个字符串,它包含缓存的信息)
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request {
request = [SDURLCache canonicalRequestForRequest:request];
NSCachedURLResponse *memoryResponse =
[super cachedResponseForRequest:request];
if (memoryResponse) {
return memoryResponse;
}
NSString *cacheKey = [SDURLCache cacheKeyForURL:request.URL];
// NOTE: We don't handle expiration here as even staled cache data is
// necessary for …Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我想有一个计数器来跟踪创建的Person对象的数量.这段代码没有这样做,我怎么做到这一点?
function Person(){
this.name = "Peter";
this.counter = this.counter + 1;
alert(this.counter);
}
Person.prototype.counter = 0;
var p1 = new Person;
var p2 = new Person;
Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题,即确定如何检测UIView被触及和UIView被点击.当它被触及时,我希望UIView改变它的背景颜色.当它被触摸时,我希望UIView执行某些任务.我想知道我是如何解决这个问题的.
-(void)viewDidLoad
{
UITapGestureRecognizer *dismissGestureRecognition = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDismissDoubleTap:)];
dismissGestureRecognition.numberOfTapsRequired = 1;
[sectionDismissDoubleView addGestureRecognizer:dismissGestureRecognition];
UITapGestureRecognizer *dismissGestureDownRecognition = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissGestureDownRecognition:)];
dismissGestureRecognition.numberOfTouchesRequired = 1;
[sectionDismissDoubleView addGestureRecognizer:dismissGestureDownRecognition];
}
- (void)handleDismissDoubleTap:(UIGestureRecognizer*)tap {
SettingsDismissDoubleViewController *settingsDouble = [[SettingsDismissDoubleViewController alloc] initWithNibName:@"SettingsDismissDoubleViewController" bundle:nil];
[self.navigationController pushViewController:settingsDouble animated:YES];
}
- (void)dismissGestureDownRecognition:(UIGestureRecognizer*)tap {
NSLog(@"Down");
}
Run Code Online (Sandbox Code Playgroud) 我试图根据这篇文章用git设置hudson ,但是在构建过程中我仍然会遇到git错误:
FATAL: Could not apply tag-PROJECTNAME-ID
...
Caused by: hudson.plugins.git.GitException: Command returned status code 128:
*** Please tell me who you are.
Run Code Online (Sandbox Code Playgroud)
running:git config --global user.name显示有效数据,.gitconfig 可访问.
如何纠正这些错误?
考虑一个视图控制器,当单击按钮时需要滑出(或隐藏)状态栏.
- (void) buttonClick:(id)sender
{
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
}
Run Code Online (Sandbox Code Playgroud)
上面有效地隐藏了状态栏,但没有适当调整根视图的大小,在顶部留下20像素的间隙.
我期望的是根视图扩展到以前状态栏使用的空间(动画,持续时间与状态栏动画相同).
这样做的正确方法是什么?
(我知道有很多类似的问题,但我找不到任何关于按需隐藏状态栏而不是隐藏它以显示新的视图控制器)
显然,以下作品......
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = self.view.frame;
frame.origin.y -= 20;
frame.size.height += 20;
self.view.frame = frame;
}];
Run Code Online (Sandbox Code Playgroud)
......但有缺点:
UIViewAutoresizingFlexibleTopMargin和UIViewAutoresizingFlexibleHeight.[self.view setNeedsLayout]隐藏状态栏后调用.[self.view setNeedsDisplay]隐藏状态栏后调用.wantsFullScreenLayout为YES隐藏状态栏之前和之后.当确保可以通过版本控制(git)将iPhone项目作为精确副本安装到全新的计算机中时,我意识到.gitignore文件丢失了.在版本控制下添加,但现在想将该文件添加到Xcode项目中以便于查看和编辑.
使用" Control-click+ Add Files to myProject..."弹出菜单时,我看不到任何以.(这是一个点)开头的文件名.如何将我的.gitignore文件添加到Xcode项目中?
我在iPod Touch 2.2.1设备上构建并运行了一个iPhone应用程序,遇到了一些问题并进行了修复尝试.现在尝试重新构建和运行应用程序会给出两(2)个错误弹出注释:
无法从设备接收消息[确定]
谷歌找不到这个!设备本身正在愉快地工作,我甚至可以启动并使用我正在尝试安装的应用程序.iTunes看起来仍然连接......可能是什么问题?

我遇到了UITableView的ios 5的didSelectRowAtIndexPath问题,这在ios 4中是正确的.
我第一次点击表中的任何一行时,该方法不会被调用.一旦我选择了另一行,它就会调用didSelectRowAtIndexPath,但会传递最后一个indexPath.
我已经设置了tableView.delegate,它可以在ios4中正确运行.
MainView.xib
UITabBarController
--UINavigationController
--**UITableViewController**
Run Code Online (Sandbox Code Playgroud)
有什么建议?
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [[NSString alloc]initWithFormat:@"%d",indexPath.row];
return cell; …Run Code Online (Sandbox Code Playgroud) iphone ×4
ios ×3
xcode ×3
objective-c ×2
afnetworking ×1
caching ×1
git ×1
gitignore ×1
hudson ×1
installation ×1
ios5 ×1
ipod-touch ×1
javascript ×1
jenkins ×1
selector ×1
statusbar ×1
uistatusbar ×1
uitableview ×1
xcasset ×1