小编Jos*_*ell的帖子

- [NSDateFormatter dateFromString:]返回nil

    NSString *lower = [NSString stringWithFormat:@"%@",[newDates objectAtIndex:0]];
    NSString *higher = [NSString stringWithFormat:@"%@",[newDates objectAtIndex:[newDates count]-1]];
    NSLog(@"%@",lower);
    NSLog(@"%@",higher);

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    NSDate *dtLower = [df dateFromString:lower];

    NSDate *dtHigher = [df dateFromString:higher];
    [df release];
    NSDateFormatter *df1 = [[NSDateFormatter alloc] init];
    [df1 setDateFormat:@"yyyy-MM-dd"];
    NSString * lowerDate = [df1 stringFromDate:dtLower];
    NSString * higherDate = [df1 stringFromDate:dtHigher];
    UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 31, self.view.frame.size.width, 30)];
    [dateLabel setTextColor:[UIColor grayColor]];
    dateLabel.text = [NSString stringWithFormat:@"%@ - %@",lowerDate,higherDate];
    [self.view addSubview:dateLabel];
Run Code Online (Sandbox Code Playgroud)

控制台的输出lower和输出higher是: …

cocoa-touch objective-c nsdateformatter ios

2
推荐指数
1
解决办法
3687
查看次数

获取正在运行的应用程序列表(从Applescript转换?)

我想监视正在运行的应用程序.它在AppleScript中很简单,但我找不到有关如何在Objective-C中执行相同操作的任何有用信息.

on run
tell application "System Events" to get name of every process
end run
Run Code Online (Sandbox Code Playgroud)

macos cocoa applescript objective-c

2
推荐指数
1
解决办法
1858
查看次数

检查发布到Facebook Feed的成功

在我的应用程序用户可以发布到他的Facebook提要,我需要知道发布是否成功.在Facebook开发者的页面上,我发现如果帖子成功,该应用程序会收到一个post_id.所以我可以检查一下post_id; 如果不是nil这意味着用户已发布到他的Feed,但我怎么能得到post_id?

cocoa-touch facebook objective-c ios

2
推荐指数
1
解决办法
3484
查看次数

我是怎么意味着释放从类方法返回的数组?

我有一段代码调用方法返回NSMutableArray如下:

+(NSMutableArray *)method {

NSMutableArray *rgb = [[NSMutableArray alloc] initWithObjects:....., nil];

    return rgb;

}
Run Code Online (Sandbox Code Playgroud)

它每次被叫时都会泄漏.放下[rgb release];后return似乎不起作用.放在它之前return使我的应用程序崩溃.同时加入autorelease使我的应用程序崩溃.建议?

cocoa-touch memory-leaks memory-management objective-c ios

2
推荐指数
1
解决办法
584
查看次数

比较NSStrings和有关NSNumbers的警告

有时JSON会(null)从数据库中返回数据,因此我会检查它是否返回了数据(null).

else if (NSOrderedSame == [[clubsArray objectAtIndex:indexPath.row] compare:@"(null)"] )
Run Code Online (Sandbox Code Playgroud)

但Xcode警告我

不兼容的Objective-C类型'struct NSString*',当从不同的Objective-C类型传递'compare:'的参数1时,预期'struct NSNumber*'

我将NSStrings 添加到该数组中,所以我很困惑为什么它在讨论结构.

NSString *clubNameReturned = [message objectForKey:@"clubname"];
[clubsArray addObject:clubNameReturned];
Run Code Online (Sandbox Code Playgroud)

有人能够对这里发生的事情有所了解吗?

代码按照我的预期执行,但我不想做一些不正确的事情.

comparison cocoa-touch objective-c compiler-warnings ios

2
推荐指数
1
解决办法
1063
查看次数

在@interface声明中理解"(私有)"的这种用法

我看过这样编写的代码:

@interface AViewController(Private)
Run Code Online (Sandbox Code Playgroud)

我想知道(Private)提交到App Store时是否意味着什么?一般来说意味着什么?

cocoa-touch interface objective-c method-declaration ios

2
推荐指数
1
解决办法
386
查看次数

错误:在NSMutableArray上使用addObjects:时出现"无法识别的选择器"

执行时

[self.blockViews addObject:curBlockView];
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

2011-07-01 13:35:26.240 Block Breaker [42061:207] - [__ NSArrayI addObject:]:无法识别的选择器发送到实例0x4e037a0

我对Objective-C很新.这是我的init方法吗?

//
//  GameEngine.h
//  Block Breaker
//
//  Created by Chris Muench on 7/1/11.
//  Copyright 2011 N/A. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface GameEngine : NSObject {
    NSMutableArray *blockViews;
    int numBlockRows;
    int score;
}
@property (nonatomic, copy) NSMutableArray *blockViews;
@property int numBlockRows;
@property int score;

- (void) setup;
- (void) setupBlocks;
@end


//
//  GameEngine.m
//  Block Breaker
//
//  Created by …
Run Code Online (Sandbox Code Playgroud)

properties objective-c nsmutablearray nsarray

2
推荐指数
1
解决办法
2496
查看次数

UIButton在UItableViewCell中不起作用

我有一个由标签和两个按钮组成的视图,我将其命名为UIView *footerView,因为我在表视图的最后一部分实现了这一点.我有这种说法成为视图的indexPath.section = 3使用[cell.contentView addSubview: footerView]

这是我的问题:

我可以在单元格内看到视图.但我无法点击按钮,因为单元格被选中而不是按钮(在单元格内).

我该如何克服这个问题?我的按钮甚至不可选!

这是代码... In cellForRowAtIndexPath:

if (section == 3){

    cell = nil;
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    if (indexPath.row ==0){

        cell.contentMode = UIViewContentModeScaleToFill;
        [cell.contentView addSubview:self.footerView];

    }

}
Run Code Online (Sandbox Code Playgroud)

页脚视图(如果有人需要看到这个):

 UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 3, 300, 44)];
textView.text = @"Terms and Conditions: Lorem ipsum dolor sit amet, con- sectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut"; …
Run Code Online (Sandbox Code Playgroud)

objective-c uibutton uitableview uiview ios

2
推荐指数
1
解决办法
4418
查看次数

2
推荐指数
1
解决办法
1万
查看次数

在UIScrollView中更改每个UILabel的颜色

是否有可能遍历UILabel我的所有s UIScrollview并改变颜色?

objective-c uilabel

2
推荐指数
1
解决办法
1978
查看次数