这是使用浮动对象初始化NSArray的有效方法吗?
NSArray *fatArray = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:6.9],
[NSNumber numberWithFloat:4.7],
[NSNumber numberWithFloat:6.6],
[NSNumber numberWithFloat:6.9],nil];
Run Code Online (Sandbox Code Playgroud)
它工作正常,只是想确保我走在正确的轨道上.
加里
只是一个简单的问题,如果我可以,我一直(自学习obj-c)写入int属性如下...
@property(nonatomic, assign) int myValue;
Run Code Online (Sandbox Code Playgroud)
我现在认为这可能是矫枉过正的,我不妨写一下......
@property int myValue;
Run Code Online (Sandbox Code Playgroud)
只是好奇,我知道"assign"是默认行为,"nonatomic"可以快一点......
祝一切顺利
加里
我正在使用UITableView
with UITableViewCells
,我想要停止列表顶部和底部的"结束"滚动,您可以在最顶部的单元格上下拉以显示背景(有时用于刷新)无论如何只是让单元格的顶部边缘成为"绝对顶部"?所以视图只显示细胞?
在Xcode_3.1.2中进行调试时,我非常确定我能看到NSString数组的内容.但升级到3.2后我只看到以下内容......
我知道我可以使用"po planetArray"打印(gdb)中的对象,或者只需单击调试器并"将描述打印到控制台"我很好奇,因为我确信它在升级之前有效.有人知道这是什么一回事吗?
欢呼加里
编辑:数据格式化程序已打开,它显示您在上面看到的内容...
我希望在我的视图中添加一个透明背景的黑色标签(见下文)
// ADD LABEL
UILabel *label = [[UILabel alloc] init];
[label setFrame:CGRectMake(124, 312, 72, 35)];
[label setText:@"Yay!"];
[label setTextAlignment:UITextAlignmentCenter];
[[self view] addSubview:label];
[label release];
Run Code Online (Sandbox Code Playgroud)
当我添加标签时,它总是在白色背景上显示黑色文字.我查看了NIB,我可以看到使这项工作的唯一方法是将background> color> opacity设置为0,或者在Xcode中:
[label setBackgroundColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
干杯加里
释放对象后最好将指针设置为nil?多数民众赞成我一直在做的事情,只是想问一下它是否必要,良好的做法或过度杀伤?
- (void)dealloc{
[planetName release]; // NSString instance variable
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
.
- (void)dealloc{
[planetName release]; // NSString instance variable
planetName = nil;
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
干杯 - 加里 -
有没有办法检查一个集合是否为空?
NSMutableSet *setEmpty = [[NSMutableSet alloc] init];
// Code to do things...
// Check for empty set?
[setEmpty release];
Run Code Online (Sandbox Code Playgroud)
加里
如果我这样做,我只是很好奇.
NSString *fileContents;
NSError *fileError = nil;
fileContents = [[NSString stringWithContentsOfFile:fileOnDisk
encoding:NSMacOSRomanStringEncoding
error:&fileError] retain];
if(fileError != nil) {
NSLog(@"Error : %@", [fileError localizedDescription]);
}
// Other Code ...
[fileContents release];
Run Code Online (Sandbox Code Playgroud)
.
.
NSString *fileOnDisk = @"/Users/Gary/Documents/Xcode/RnD/Maya.MEL";
NSError *fileError; // Should this be *fileError = nil;
NSString *fileContents;
int status = 0;
fileContents = [[NSString stringWithContentsOfFile:fileOnDisk
encoding:NSMacOSRomanStringEncoding
error:&fileError] retain];
if(fileContents == nil) {
NSLog(@"FileError: %@", [fileError localizedDescription]);
status = 1;
} else {
NSLog(@"Success : %@", fileContents);
}
// Clean …
Run Code Online (Sandbox Code Playgroud) 我已经设置了一个从符合MKAnnotation协议的类派生的NSMutableArray对象.我为注释设置了设置标题和副标题,并使用以下方法成功将它们添加到MKMapView:
[[self customMapView] addAnnotations:locationArray];
Run Code Online (Sandbox Code Playgroud)
我现在要做的是动画引脚掉落,最初我以为我可以用Option1做到这一点,使用这一切都可行,但引脚不做动画下降.
// Option1
// WORKS FOR: pinColor YES, animatesDrop NO, LABEL YES
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
for(MKPinAnnotationView *eachView in views) {
[eachView setAnimatesDrop:YES];
[eachView setPinColor:MKPinAnnotationColorPurple];
}
}
Run Code Online (Sandbox Code Playgroud)
我的下一个猜测是尝试Option2,这似乎工作得很好,但我有两个问题.标题和副标题没有显示,我的自定义注释对象正在传入(我可以在调试器中看到它),但所包含的信息并没有传递给新的pin
.其次,这会创建一组新的MKAnnotationViews,旧版本会发生什么,是否存在内存泄漏问题?
// Option2
//FOR: pinColor YES, animatesDrop YES, LABEL NO
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"annotation_ID"];
if (pin == nil) {
pin = [[[MKPinAnnotationView alloc] initWithAnnotation: …
Run Code Online (Sandbox Code Playgroud) 我试图为UILabel上的文字设置颜色的动画来从:[黑色]到[白色]到[黑色]并重复.
- (void)timerFlash:(NSTimer *)timer {
[[self navTitle] setTextColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]];
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{[[self navTitle] setTextColor:[[UIColor whiteColor] colorWithAlphaComponent:1.0]];}
completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
.
[self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFlash:) userInfo:nil repeats:YES]];
Run Code Online (Sandbox Code Playgroud)
首先,我不确定我的方法,我的计划(如上所示)是设置动画块并使用重复的NSTimer调用它直到取消.
我的第二个问题(正如你在上面看到的)是我从黑色(alpha 0)到白色(alpha 1)的动画,但我不知道如何再次动画回黑色,所以动画无缝循环
基本上我想要的是在UILabel上脉冲的文本颜色,直到用户按下按钮继续.
我遇到了麻烦,因为你不能动画[UILabel setColor:]你可以动画[UILabel setAlpha:]所以我要去试试.
- (void)timerFlash:(NSTimer *)timer {
[[self navTitle] setAlpha:0.5];
[UIView animateWithDuration:2
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{[[self navTitle] setAlpha:0.9];}
completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
这是有效的(顺便说一句:我确实希望它停止,这就是为什么我把它连接到NSTimer,所以我可以取消它)唯一的事情就是这从midGray到nearWhite的动画然后弹出.有谁知道我会如何动画从nearWhite到midGray,所以我得到了一个很好的平滑循环?
Dave DeLong(见下文)建议的代码在修改为使用CALayer不透明度样式属性时确实有效:
UILabel *navTitle;
@property(nonatomic, retain) UILabel *navTitle;
Run Code Online (Sandbox Code Playgroud)
.
// ADD ANIMATION
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
[anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[anim setFromValue:[NSNumber …
Run Code Online (Sandbox Code Playgroud)