函数[NSArray arrayWithObjects:foo,bar,nil]将一个nil-terminted字符串列表传递给一个函数.
如果我想编写一个类似的函数,声明是什么样的,我如何遍历字符串?
NSString *latitude = [[NSString alloc] initWithFormat:@"%g°", coordinate.latitude];
NSString *longitude = [[NSString alloc] initWithFormat:@"%g°", coordinate.longitude];
self.pointLabel.text = [latitude stringByAppendingString:@", "];
self.pointLabel.text = [self.pointLabel.text stringByAppendingString:longitude];
Run Code Online (Sandbox Code Playgroud) 我确信有更好的方法可以做到这一点.我有一大堆代码用于消灭iPhone或模拟器上的DocumentsDirectory.有时我只想要一个干净的平板,有时我会对数据库进行更改,我需要重建它.
因此,在我打开我的应用程序时调用的一个函数中,我已将此代码注释掉,并在我想要重置时删除注释块.你是做什么?
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *dirContents = [fileManager directoryContentsAtPath:[paths objectAtIndex:0]];
for (int i=0; i<[dirContents count]; ++i) {
NSString* theDir = [[paths objectAtIndex:0] stringByAppendingString:[@"/" stringByAppendingString:[dirContents objectAtIndex:i]]];
NSLog(theDir);
if ([fileManager removeItemAtPath: theDir error:NULL]) {
NSLog(@"removed dir");
}
}
Run Code Online (Sandbox Code Playgroud)
我是新手iPhone开发者.如果这就像Python服务器,我只会运行一个脚本,但我不确定XCode/iPhone的约定是什么.
我在这里阅读了教程:http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application,我可以得到一个图表来显示,但我没有看到任何勾号我轴上的标记或标签设置.我有什么简单的东西可以忽略吗?下面是我创建图表的代码,我还实现了委托函数.我正在看轴和图,但不是轴刻度线或标签.
谢谢你提供的所有帮助.
- (void) showGraph {
graph = [[CPXYGraph alloc] initWithFrame: CGRectMake(0,0, 320, 320)];
CPLayerHostingView *graphView = [[CPLayerHostingView alloc] initWithFrame:CGRectMake(0,0, 320, 320)];
graphView.backgroundColor = [UIColor blueColor];
AppDelegate *t = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[t.mapVC.view addSubview:graphView];
graphView.hostedLayer = graph;
graph.paddingLeft = 20.0;
graph.paddingTop = 20.0;
graph.paddingRight = 20.0;
graph.paddingBottom = 20.0;
float minElevation = 0;
float maxElevation = 10;
float minTime = 0;
float maxTime = 5;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minTime)
length:CPDecimalFromFloat(maxTime)]; …Run Code Online (Sandbox Code Playgroud) 确定以下内容的好方法是什么.
你有一个游戏玩家的桌子,大小为N.每轮,每个玩家轮流.
你知道应该首先进入的玩家的索引,并且每个玩家将在数组中上升,并在它到达最后一个索引时循环回到0.例如,如果在索引3处的玩家先行,那么4将成为第二,而2将成为最后一个.
你如何计算一轮中最后一名球员的指数?
这是一种方式:
var startPosition = 3;
var numberOfPlayers = 10;
for (var i=0;i<numberOfPlayers;i++) {
startPosition++;
if (startPosition == numberOfPlayers) startPosition = 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个绘制圆角矩形的类,在它周围放置一个边框,中间有一段文字.
我想在文本中添加阴影/轮廓,以便文本看起来像UINavigationBar上的标题.
CoreGraphics可以实现吗?
我经常看到这个"if(self = [super init])"构造,我想知道它为什么会这样做.
- (id) init {
if (self = [super init]) {
// how could self = [super init]; ever fail?
}
return self;
}
Run Code Online (Sandbox Code Playgroud) for jr in json_reports:
jr['time_created'] = str(jr['time_created'])
Run Code Online (Sandbox Code Playgroud) 当我调用这个函数时,它似乎返回一个指针而不是一个int.当我尝试NSLog返回值时,我收到一条警告"从不兼容的指针类型传递NSLog的参数1".如果NSLog运行,它会崩溃.
这与静态方法有关吗?我怎样才能找回真正的int?
我正在使用SDK 3.0
这是有问题的功能:
+(int) getZoomFromExtent: (CLLocationCoordinate2D)bottomLeft
withTopRight:(CLLocationCoordinate2D)topRight
withPixelsX:(int)pixelsX
withPixelsY:(int)pixelsY
withMapContents: (RMMapContents*) contents;
Run Code Online (Sandbox Code Playgroud)
这是.h代码:
#import <Foundation/Foundation.h>
#import <math.h>
#import <CoreLocation/CLLocation.h>
#import "RMTile.h"
#import "RMMapContents.h"
@interface AnnasMath : NSObject {}
+(CLLocationCoordinate2D) normalizePixelCoords:(CLLocationCoordinate2D) point;
+(RMTile)tileWithCoordinate:(CLLocationCoordinate2D)point andZoom:(int)zoom;
+(NSArray *)getTileArrayWithUpperLeft:(CLLocationCoordinate2D)upperLeft andLowerRight: (CLLocationCoordinate2D)lowerRight fromZoom:(int)bottomZoom toZoom:(int)topZoom;
+(int)getTileCountWithUpperLeft:(CLLocationCoordinate2D)upperLeft andLowerRight:(CLLocationCoordinate2D)lowerRight fromZoom:(int)bottomZoom toZoom:(int)topZoom;
+(int) getZoomFromExtent: (CLLocationCoordinate2D)bottomLeft
withTopRight: (CLLocationCoordinate2D)topRight
withPixelsX:(int)pixelsX
withPixelsY:(int)pixelsY
withMapContents: (RMMapContents*) contents;
Run Code Online (Sandbox Code Playgroud)
@结束
这是.m代码的开头:
#import "AnnasMath.h"
#import <Foundation/Foundation.h>
#import <math.h>
#import "TileWrapper.h"
@implementation AnnasMath
...
Run Code Online (Sandbox Code Playgroud)
我使用它如下:
int zoom = [AnnasMath getZoomFromExtent:[[extent objectForKey:@"bottomLeft"]coordinate]
withTopRight:[[extent objectForKey:@"topRight"]coordinate]
withPixelsX:300
withPixelsY:300
withMapContents:t.mapVC.mapView.contents]; …Run Code Online (Sandbox Code Playgroud) iPhone相机工具栏为灰色且略有渐变.我相信我可以通过设置工具栏的tintColor和/或半透明来实现相同的外观.
知道我怎么能让我的工具栏看起来像相机一样吗?
这不太对劲......太黑了:
UIToolbar *tb = [[UIToolbar alloc] initWithFrame:frame];
tb.tintColor = [UIColor grayColor];
Run Code Online (Sandbox Code Playgroud) iphone ×8
cocoa-touch ×7
objective-c ×7
core-plot ×1
ios ×1
javascript ×1
math ×1
python ×1
xcode ×1