我每天都在尝试使用牙线,进行锻炼,并确保在保留和释放之间保持平衡.
这让我感到困惑.我有一个伊娃:
NSMutabledata *_alignmentData
Run Code Online (Sandbox Code Playgroud)
以及与之相关的综合属性:
// .h file
@property (nonatomic, retain) NSMutableData *alignmentData;
// .m file
@synthesize alignmentData=_alignmentData;
Run Code Online (Sandbox Code Playgroud)
我开始异步从服务器中提取数据:
self.connection =
[[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];
Run Code Online (Sandbox Code Playgroud)
并在分配了一个数据缓冲区后立即在异步回调中使用:
// This prints 0. Cool.
NSLog(@"BEFORE [_alignmentData retainCount] = %d", [_alignmentData retainCount]);
// Create a place to receive the data that will arrive asynchronously:
self.alignmentData = [NSMutableData data];
// This prints 2. Shouldn't this be 1 ?!?
NSLog(@" AFTER [_alignmentData retainCount] = %d", [_alignmentData retainCount]);
Run Code Online (Sandbox Code Playgroud)
为了使在上面分配self.alignmentData之后触发的第一个异步回调中的问题复杂化,我再次检查保留计数:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// …Run Code Online (Sandbox Code Playgroud) 我收到这个错误: -[NSCFArray insertObject:atIndex:]: attempt to insert nil
这是.m文件:
/*
IBOutlet NSTextField *textField;
IBOutlet NSTabView *tableView;
IBOutlet NSButton *button;
NSMutableArray *myArray;
*/
#import "AppController.h"
@implementation AppController
-(IBAction)addNewItem:(id)sender
{
myArray = [[NSMutableArray alloc]init];
tableView = [[NSTableView alloc] init];
[tableView setDataSource:self];
[textField stringValue];
NSString *string = [[NSString alloc] init];
string = [textField stringValue];
[myArray addObject:string];
NSLog(@"%d",[myArray count]);
NSLog(@"%@",string);
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [myArray count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
//NSString *data = [myArray objectAtIndex:rowIndex];
return [myArray objectAtIndex:rowIndex];
} …Run Code Online (Sandbox Code Playgroud) 我可以获得AES-128位算法的链接任何示例代码请帮忙
这是我的问题.我无法为我的navigationBar设置名称..下面是我试过的一些但无济于事.
- (void)viewDidLload {
[super viewDidLoad];
self.title = @"Food";
}
- (void)viewDidLload {
[super viewDidLoad];
[self.setTitle:@"Food"];
}
- (void)viewDidLload {
[super viewDidLoad];
MyTableViewController *myTableViewController = [[MyTableViewController alloc] init];
myTableViewController = @"Food";
}
Run Code Online (Sandbox Code Playgroud)
任何一种灵魂?
我是Objective C的新手,但拥有丰富的C++经验.
我有一个名为bOn的成员变量,我已将其声明为readonly属性.然后我合成它.
但是,编译器不会让我读它,说"实例变量'bOn'被声明为受保护的".如果我没有合成,我会理解这个错误.
这是我的片段:
@interface Button : NSObject
{
. . .
BOOL bOn;
}
@property (nonatomic, readonly) BOOL bOn;
Run Code Online (Sandbox Code Playgroud)
我在哪里使用它:
-(void) updateForButtonLeft:(Button *)butLeft Right:(Button *)butRight
{
BOOL bLeft = butLeft->bOn;
. . .
Run Code Online (Sandbox Code Playgroud)
那我还有什么别忘了呢?
谢谢,
戴夫.
如果我有一个带有几个字典对象的NSArray(或可变数组)(每个字典都是Person),就像这样:
[
{ forename: chris, surname: smith, age: 22 }
{ forename: paul, surname: smith, age: 24 }
{ forename: dave, surname: jones, age: 21 }
{ forename: alan, surname: jones, age: 26 }
{ forename: cecil, surname: reeves, age: 32 }
{ forename: pablo, surname: sanchez, age: 42 }
]
Run Code Online (Sandbox Code Playgroud)
我如何将它分成四个数组的数组,按姓氏(并在该名称中)排序,如下所示:
[
[
{ forename: alan, surname: jones, age: 26 }
{ forename: dave, surname: jones, age: 21 }
]
[
{ forename: cecil, surname: reeves, age: 32 } …Run Code Online (Sandbox Code Playgroud) 我创建了一个视图控制器viewsampleViewController ..它有两个方法setname和getname ..我为该视图控制器创建一个测试用例.我的testcase名称是newTestCase,方法名称是testName.
#import "newTestCase.h"
#import "viewsampleViewController.h"
@implementation newTestCase
Run Code Online (Sandbox Code Playgroud)
在我的testName方法中,
-(void)testName{
NSString *b=@"hello";
v =[[viewsampleViewController alloc] init];
STAssertNotNil(v,@"v doesnt created");
[v setuname:@"hello"];
NSString *a=[v getuname];
STAssertEquals(b,a,@"error:name not equal");
[v release];
}
-(void)setUp{
v=[viewsampleViewController alloc];
}
-(void) tearDown{
[v release];
}
Run Code Online (Sandbox Code Playgroud)
当我建立我有一个错误
Ld "build/Debug-iphoneos/Unit test.octest/Unit test" normal armv6
cd /Users/anande/Documents/viewsample
setenv IPHONEOS_DEPLOYMENT_TARGET 3.1.3
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -bundle -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk -L/Users/anande/Documents/viewsample/build/Debug-iphoneos -F/Users/anande/Documents/viewsample/build/Debug-iphoneos -F/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/Developer/Library/Frameworks -filelist "/Users/anande/Documents/viewsample/build/viewsample.build/Debug-iphoneos/Unit test.build/Objects-normal/armv6/Unit test.LinkFileList" -dead_strip -framework Foundation -framework SenTestingKit -miphoneos-version-min=3.1.3 -o "/Users/anande/Documents/viewsample/build/Debug-iphoneos/Unit test.octest/Unit test"
Undefined symbols: …Run Code Online (Sandbox Code Playgroud) 我下载了安装在我的仪表板区域的这个Mac应用程序,这些特殊应用程序还是只是安装在我计算机上特定区域的常规可可应用程序?
这是应用程序:http://bit.ly/8xKiH
我很确定有更好的方法来实现我想要做的事情,我只是尝试不同的途径来看看什么对我最有用......所以我有一个带有4个段的UISegmentedController.我在界面生成器中给了每个标题,我想要做的是当他们按某个片段时会播放相应的视频.我正在使用webview,因为......这就是我所知道的...到目前为止......这是我的代码:
-(IBAction) getVideo: (id) sender
{
NSURL *videoURl;
NSString *videoURLString;
NSString *video;
video = [videoChoice titleForSegmentAtIndex:
videoChoice.selectedSegmentIndex];
if (video = @"Shimmy") {
videoURLString = [[NSString alloc] initWithFormat:
@"http://www.andalee.com/iPhoneVideos/mov.MOV"];
} else if (video = @"Camel") {
videoURLString = [[NSString alloc] initWithFormat:
@"http://www.andalee.com"];
} else {
videoURLString = [[NSString alloc] initWithFormat:
@"http://www.yahoo.com"];
}
videoURl = [[NSURL alloc] initWithString: videoURLString];
[videoView loadRequest: [NSURLRequest requestWithURL: videoURl]];
[videoURl release];
[videoURLString release];
}
Run Code Online (Sandbox Code Playgroud)
因此,当我使用它(视频= @"Shimmy")时,它直接进入视频,但对于每个片段都是相同的...现在,如果我将其更改为(video == @"Shimmy"),它会直接转到其他部分没有其他的.顺便说一句,现在的链接只是试图了解机制.
我正在阅读更多iPhone编程3,我不记得<>符号是什么.我知道这是符合协议的一类,但我不知道它是什么,在这个例子中的核心数据部分谈论NSFetchedResultsController.这是代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
Run Code Online (Sandbox Code Playgroud)
谢谢!
NSMutableString *ms = [[NSMutableString alloc]init];
[ms appendFormat:@"element %ld",1];
[ms appendFormat:@"element %ld",2];
NSMutableString *ms2 = [ms mutableCopy];
NSLog(@"ms retain count:%lu",ms.retainCount);
NSLog(@"ms2 retain count:%lu",ms2.retainCount);
NSValue *sw = [NSValue valueWithNonretainedObject:ms2];
NSMutableArray *a = [NSMutableArray array];
[a addObject:ms];
[a addObject:sw];
NSLog(@"ms retaincount %lu",ms.retainCount);
NSLog(@"ms2 retaincount %lu",ms2.retainCount);
Run Code Online (Sandbox Code Playgroud) 我正在桌面视图上构建RSS提要.当我运行应用程序时,我的iPhone可以在ipad中顺利运行,它崩溃并显示"因未捕获的异常终止应用程序'NSInvalidUnarchiveOperationException',原因:'无法实例化名为UIRefreshControl的类'"
我试图在我的ipad模拟器上运行应用程序,它也可以顺利运行.我可以知道那是什么问题吗?
谢谢
objective-c ×9
iphone ×7
cocoa ×2
ios ×2
xcode ×2
aes ×1
cocoa-touch ×1
encryption ×1
if-statement ×1
ios6 ×1
ipad ×1
macos ×1
nsarray ×1
nsdata ×1
properties ×1
readonly ×1
release ×1
retain ×1
retaincount ×1
syntax ×1
unit-testing ×1