小编And*_*son的帖子

如何将nil-terminted字符串列表传递给Objective-C函数?

函数[NSArray arrayWithObjects:foo,bar,nil]将一个nil-terminted字符串列表传递给一个函数.

如果我想编写一个类似的函数,声明是什么样的,我如何遍历字符串?

iphone objective-c

3
推荐指数
1
解决办法
1127
查看次数

有没有更简洁的方法来连接Cocoa中的这些字符串?

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 cocoa-touch objective-c

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

你的方法是什么......在iPhone开发过程中消灭你的DocumentsDirectory?

我确信有更好的方法可以做到这一点.我有一大堆代码用于消灭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的约定是什么.

iphone xcode cocoa-touch

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

iPhone Core-Plot Tick Marks不显示

我在这里阅读了教程: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)

iphone cocoa-touch objective-c core-plot

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

什么是我无法弄清楚的优雅模数?

确定以下内容的好方法是什么.

你有一个游戏玩家的桌子,大小为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)

javascript math

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

你能用Core Graphics绘制文字阴影/轮廓吗?

我有一个绘制圆角矩形的类,在它周围放置一个边框,中间有一段文字.

我想在文本中添加阴影/轮廓,以便文本看起来像UINavigationBar上的标题.

CoreGraphics可以实现吗?

iphone cocoa-touch objective-c

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

实现像这样的Objective C init方法有什么意义?

可能重复:
在Objective-C中我为什么要检查self = [super init]是不是nil?

我经常看到这个"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)

iphone cocoa-touch objective-c ios

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

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

为什么这个函数返回一个指针?

当我调用这个函数时,它似乎返回一个指针而不是一个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 cocoa-touch objective-c

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

如何设置UIToolbar的样式,使其看起来像标准的iPhone相机工具栏?

iPhone相机工具栏为灰色且略有渐变.我相信我可以通过设置工具栏的tintColor和/或半透明来实现相同的外观.

知道我怎么能让我的工具栏看起来像相机一样吗?

这不太对劲......太黑了:

UIToolbar *tb = [[UIToolbar alloc] initWithFrame:frame];
tb.tintColor = [UIColor grayColor];
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c

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

标签 统计

iphone ×8

cocoa-touch ×7

objective-c ×7

core-plot ×1

ios ×1

javascript ×1

math ×1

python ×1

xcode ×1