小编Wri*_*sCS的帖子

在没有循环或条件的情况下打印1到1000

任务:打印数字从1到1000,不使用任何循环或条件语句.不要只写1000次printf()cout语句.

你会怎么用C或C++做到这一点?

c c++ printf

323
推荐指数
52
解决办法
25万
查看次数

iOS SDK - 以编程方式生成PDF文件

在我的诚实意见中,使用CoreGraphics框架是一项繁琐的工作,当涉及到以编程方式绘制PDF文件时.

我想以编程方式创建一个PDF,使用我的应用程序中的视图中的各种对象.

我很想知道iOS SDK是否有任何好的PDF教程,可能是库中的一个下降.

我已经看过这个教程,PDF创建教程,但它主要是用C语言编写的.寻找更多的Objective-C风格.这似乎是一种写入PDF文件的荒谬方式,必须计算线和其他对象的放置位置.

void CreatePDFFile (CGRect pageRect, const char *filename) 
{   
    // This code block sets up our PDF Context so that we can draw to it
    CGContextRef pdfContext;
    CFStringRef path;
    CFURLRef url;
    CFMutableDictionaryRef myDictionary = NULL;

    // Create a CFString from the filename we provide to this method when we call it
    path = CFStringCreateWithCString (NULL, filename,
                                      kCFStringEncodingUTF8);

    // Create a CFURL using the CFString we just defined
    url = CFURLCreateWithFileSystemPath …
Run Code Online (Sandbox Code Playgroud)

iphone pdf-generation objective-c ipad ios

79
推荐指数
3
解决办法
8万
查看次数

升级到xcode 4错误没有要编译的体系结构

对于我的应用程序所依赖的所有库项目,升级到xcode 4后出现错误.

[BEROR]没有要编译的体系结构(ONLY_ACTIVE_ARCH = YES,活动arch = i386,VALID_ARCHS = armv6).

xcode ios xcode4

41
推荐指数
3
解决办法
3万
查看次数

如何在Xcode 4中进行远程调试?

有没有办法在Xcode 4中进行远程调试?此问题的先前答案是针对Xcode 3和Apple删除了Xcode指南中的特定调试(我假设)涵盖了远程调试.

对于踢球,我一直在这样做lldb,但如果有一种方法,gdb那就是伟大的.到目前为止,我已经能够像这样在远程计算机上启动调试服务器

/ usr/bin/ssh -l $ {REMOTE_USER} -f $ {REMOTE_HOST}"/ Developer/usr/bin/debugserver localhost:12345"

然后我可以lldb从终端手动登录并进行调试.我希望能够做的是至少lldb在Xcode中启动一个裸会话然后手动启动process connect connect://hostname:port.

debugging xcode lldb

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

以编程方式在Mac OS X中获取屏幕大小

我可以使用以下命令返回屏幕尺寸:

- (void) getScreenResolution {

    NSArray *screenArray = [NSScreen screens];
    NSScreen *mainScreen = [NSScreen mainScreen];
    unsigned screenCount = [screenArray count];
    unsigned index  = 0;

    for (index; index < screenCount; index++)
    {
      NSScreen *screen = [screenArray objectAtIndex: index];
      NSRect screenRect = [screen visibleFrame];
      NSString *mString = ((mainScreen == screen) ? @"Main" : @"not-main");

      NSLog(@"Screen #%d (%@) Frame: %@", index, mString, NSStringFromRect(screenRect));
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

屏幕#0(主要)框架:{{0,4},{1344,814}}

有没有一种方法格式化{1344, 814}1344x814


编辑:

这非常有效:

- (NSString*) screenResolution {

    NSRect screenRect;
    NSArray *screenArray …
Run Code Online (Sandbox Code Playgroud)

macos cocoa resolution screen

31
推荐指数
5
解决办法
3万
查看次数

UITableViewCell,具有动态高度的UITextView

我需要制作一个UITableViewCell包含大量文本的内容.我知道我可以添加UITextView到我的单元格,但每个条目都不会有相同数量的文本.

我知道我可以控制UITableViewCellwith 的高度:-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath,但那不是我想要的.

场景1:

 ---------------
| First Cell    |
 ---------------
 ---------------
| Second Cell   |
| with some     |
| text.         |
 ---------------
 ---------------
| Third Cell    |
 ---------------
Run Code Online (Sandbox Code Playgroud)

场景2:

 ---------------
| First Cell    |
 ---------------
 ---------------
| Second Cell   |
| with some     |
| more text and |
| an unknown    |
| cell height.  | 
 ---------------
 ---------------
| Third Cell    |
 ---------------
Run Code Online (Sandbox Code Playgroud)

iphone uitableview uitextview ios

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

对UITabBarController的开始/结束外观转换的不平衡调用

我有一个UITabBarController,在初始运行时,我想覆盖登录视图控制器但收到错误.

对<UITabBarController:0x863ae00>的开始/结束外观转换的不平衡调用.

下面是代码.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    UIViewController *lessonVC = [[[LessonViewController alloc] initWithNibName:@"LessonViewController" bundle:nil] autorelease];

    UIViewController *programVC = [[[ProgramViewController alloc] initWithNibName:@"ProgramViewController" bundle:nil] autorelease];

    UIViewController *flashcardVC = [[[FlashCardViewController alloc] initWithNibName:@"FlashCardViewController" bundle:nil] autorelease];

    UIViewController *moreVC = [[[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil] autorelease];

    UINavigationController *lessonNVC = [[[UINavigationController alloc] initWithRootViewController:lessonVC] autorelease];

    UINavigationController *programNVC = [[[UINavigationController alloc] initWithRootViewController:programVC] autorelease];

    UINavigationController …
Run Code Online (Sandbox Code Playgroud)

iphone uitabbarcontroller transitions ipad

27
推荐指数
3
解决办法
3万
查看次数

带有Xcode 4.2的iOS 5.1和带有iPad 3的视网膜

我有一台配备Mac OS X Snow Leopard的Mac,我可以添加iOS 5.1吗?

随着iPad 3的新分辨率,我们将如何处理图像,因为如果应用程序将在iPhone 3GS,4和iPad 3中运行,我认为我们应该有3个不同名称的图像,如@ 3x.png或..谢谢.

xcode ipad ios retina-display

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

MPMoviePlayerController重定向纵向到横向和回到纵向(iOS 4.1)

从iOS 3.2开始,MPMoviePlayerController类允许在视图层次结构中嵌入电影.现在我面临这个问题:我通过放置一个MPMoviePlayerController实例来创建我的纵向视图.当用户触摸"全屏"按钮时,此视图以全屏模式进入,但视图仍保持纵向.当用户旋转设备时,全屏电影视图不会自动旋转,因为我的应用禁止横向界面方向.因此,为了允许电影播放器​​全屏视图的自动旋转,我改变了我的视图控制器shouldAutorotateToInterfaceOrientation:方法如果 - 并且仅当 - 电影播放器​​处于全屏模式时返回YES.这非常有效:当用户全屏进入然后旋转到横向时,播放器会自动旋转到横向并填充整个屏幕.

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
        return(YES);
    }

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return([movieController isFullscreen]);
    }

return(NO);
}
Run Code Online (Sandbox Code Playgroud)

现在,当我在全景视图中触摸"完成"按钮的同时保持横向状态时,会出现问题.全屏关闭,然后我看到的是我的原始视图自动旋转:但我不希望这种自动旋转.

部分但不可接受的解决方案是侦听"MPMoviePlayerDidExitFullscreenNotification",如果界面旋转为横向,则强制重定向以使用未记录的私有函数:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]
Run Code Online (Sandbox Code Playgroud)

这有效但不可接受,因为禁止使用此方法.

我试图强制使用方向,[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]但因为我在Tab栏中这不起作用(UITabBar仍然是横向大小).

谢谢你的帮助

iphone uiinterfaceorientation

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

UIImageView手势(缩放,旋转)问题

我想对UIImageView缩放,旋转进行2次操作,我有2个问题:

答:我为ex做了缩放操作.当我尝试进行旋转时,将UIImageView其设置为初始大小,我想知道如何保持缩放UIImageView并从缩放图像进行旋转.

B.我想将缩放操作与旋转相结合,我不知道如何实现这一点:

- (void)viewDidLoad 
{
    foo = [[UIImageView alloc]initWithFrame:CGRectMake(100.0, 100.0, 600, 800.0)];
    foo.userInteractionEnabled = YES;
    foo.multipleTouchEnabled  = YES;
    foo.image = [UIImage imageNamed:@"earth.jpg"];
    foo.contentMode = UIViewContentModeScaleAspectFit;
    foo.clipsToBounds = YES;

    [self.view addSubview:foo];
}

//---pinch gesture--- 
UIPinchGestureRecognizer *pinchGesture =
[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[foo addGestureRecognizer:pinchGesture]; 
[pinchGesture release];

//---rotate gesture--- 
UIRotationGestureRecognizer *rotateGesture =
[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotateGesture:)];
[foo addGestureRecognizer:rotateGesture]; 
[rotateGesture release];

//---handle pinch gesture--- 
-(IBAction) handlePinchGesture:(UIGestureRecognizer *) sender {
    NSLog(@"Pinch");
    CGFloat factor = [(UIPinchGestureRecognizer *) …
Run Code Online (Sandbox Code Playgroud)

iphone zoom rotation uiimageview pinch

24
推荐指数
3
解决办法
3万
查看次数