小编Wri*_*sCS的帖子

如何在继续执行下一个命令之前让程序等待异步NSURLConnection完成?

在进入下一行代码之前,如何让我的程序等待异步NSURLConnection完成?

SetDelegate *sjd= [SetDelegate alloc];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:post delegate:sjd];
[connection start];
Run Code Online (Sandbox Code Playgroud)

这是我开始连接的方式,我处理委托中收到的数据,但我想等待连接结束,然后继续主要是因为这是在for循环中,它必须为我的数据库中的每个元素运行.

我需要将数据从手机数据库放到远程数据库中,并在数据成功放入手机数据库中的数据后删除.我正在浏览手机数据库中的每个元素并开始连接,这就是为什么我不知道如何从循环中完成下一个操作.当谈到Objective-c编程时,我是初学者,所以我不确定这是否是正确的方法

使调用同步不是一个选项,因为它会阻止程序,我有一个应该显示的进度条.

web-services ios

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

合并两个UIImages

我有imageA(取自用户的iPhone相机)和imageB,一个带有傻傻的寄宿生(例如)的图像,有足够的透明alpha空间.

我想要做的是合并这两个图像,将imageB放在imageA上,然后将它们保存为imageC用于其他工作.

有没有办法做到这一点?

干杯

到目前为止我已经有了这个

-(void)merge
{
    CGSize size = CGSizeMake(320, 480);
    UIGraphicsBeginImageContext(size);

    CGPoint thumbPoint = CGPointMake(0,0);
    UIImage *imageA = imageView.image;
    [imageA drawAtPoint:thumbPoint];

    UIImage* starred = [UIImage imageNamed:@"imageB.png"];

    CGPoint starredPoint = CGPointMake(0, 0);
    [starred drawAtPoint:starredPoint];

    UIImage *imageC = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageView.image = imageC;
}
Run Code Online (Sandbox Code Playgroud)

我看不到/不知道我在这里做错了什么

image uiimage ios4

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

iPhone导航栏的默认UIColor

谁能告诉我RGB的默认iPhone导航栏蓝色?我知道您通常可以通过设置来设置默认颜色

self.navigationBarTintColor = nil;
Run Code Online (Sandbox Code Playgroud)

但是,在这种情况下,这不起作用,所以我需要设置准确的蓝色.

谢谢你的回答,Doonot

iphone rgb uicolor navigationbar

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

textFieldShouldBeginEditing + UIKeyboardWillShowNotification + OS 3.2

我在UIView上有多个文本字段.

我在textFieldShouldBeginEditing方法中退出前一个textField,执行以下事件序列

  • 收到对应于隐藏前一个字段的键盘的字段的UIKeyboardWillHideNotification.

  • 方法textFieldShouldBeginEditing返回YES然后

  • 收到UIKeyboardWillShowNotification,显示当前字段的键盘.

但是,在OS 3.2中,即使textFieldShouldBeginEditing返回YES,也不会收到当前字段的UIKeyboardWillShowNotification.

该逻辑适用于OS <3.2

我可能做错了什么想法?

列在我的代码的一部分下面(xib中只有两个文本字段).

我需要在keyboardWillShow和keyboardWillHide上执行一组操作查看在OS 3.2和OS <3.2中运行代码的区别

任何人都可以解释行为上的差异吗?

.H

@interface ExampleViewController : UIViewController  
{
    IBOutlet UITextField *numericTextField;
    IBOutlet UITextField *alphaTextField;   
    UITextField *lastTextField;
    int lastCursorPos;
    int cursorPosition;
    NSMutableArray *textFields;
}

@property (nonatomic, retain) UITextField *lastTextField;
@property (nonatomic, retain) NSMutableArray *textFields;

@end
Run Code Online (Sandbox Code Playgroud)

.M

- (void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
                                                 name:UIKeyboardWillShowNotification object:self.view.window]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) 
                                                 name:UIKeyboardWillHideNotification object:self.view.window]; 

    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.textFields = [[NSMutableArray alloc] initWithCapacity:2];
    [self.textFields insertObject:alphaTextField atIndex:0];
    [self.textFields insertObject:numericTextField atIndex:1];
    cursorPosition = …
Run Code Online (Sandbox Code Playgroud)

iphone sdk uikeyboard

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

目标C:检测摇动

我正在使用像这样的摇动api:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 
{
    if (event.subtype == UIEventSubtypeMotionShake)
    {
        [img stopAnimating];    
    }
}
Run Code Online (Sandbox Code Playgroud)

如何检测到摇晃已停止?

objective-c accelerometer shake

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

iOS CoreLocation Altitude

在iOS 4.0之前,CoreLocation正确报告高度,现在它总是报告为0英尺.

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    NSString *tLatitude  = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]; 
    NSString *tLongitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude];
    /*  the following returns 0 */
    NSString *tAltitude  = [NSString stringWithFormat:@"%i",    newLocation.altitude];

    /* theres more code, but it's not relevant, 
                      and this worked prior to iOS 4.0*/
    [manager stopUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)

不在设备或模拟器上工作,是否还有其他人遇到此问题?

iphone core-location ios altitude cllocationdistance

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

将变换后的图像层应用于renderInContext:

背景

我正在使用Erica Saduns Cookbook示例Chapter 8, Example 14 — Resize and Rotate来显然调整大小并旋转一个UIImageView.

等级制度

1.)条纹背景视图.

2.)可以调整大小和旋转的交互式视图.

3.)具有透明部分的叠加图像.此视图在128处开始y轴,为768x768.

4.)上方和下方3,高度为2视图128.

******见下面的照片示例****

问题

目前,我可以将整个视图的图层保存到照片库中[[[self view] layer] renderInContext:,并且#2的转换是正确的.但是,我需要一种方法来保存768x768 (照片示例中的浅绿色)框架,其中仅包括#2#3,包括#2的转换.如果我使用[[#2 layer] renderInContext:,我会得到原始图像,而不是转换.(参见下面的#参考屏幕截图.

CGSize deviceSpec;
if ( IDIOM == IPAD ) { deviceSpec =CGSizeMake(768,768); } else { deviceSpec =CGSizeMake(320,480); }
if (  scale > 1.5  ) {
    UIGraphicsBeginImageContextWithOptions(deviceSpec, NO, scale);
} else {
    UIGraphicsBeginImageContext( deviceSpec );
}        

    CGContextRef …
Run Code Online (Sandbox Code Playgroud)

core-graphics layer calayer ipad ios

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

修剪文件扩展名UITableView

我想从NSMutableArray表格单元格中的文本修剪文件扩展名.

NSMutableArray *theFiles = [NSMutableArray new];
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:@"/Test"];
for (NSString *s in fileList){
    [theFiles addObject:fileList];
}
cell.textLabel.text = theFiles[indexPath.row];
return cell;
Run Code Online (Sandbox Code Playgroud)

这列出例如"Xylophone.m4r"我想删除.m4r.

trim nsstring nsmutablearray

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

关于NSDictionary的NSPredicate

我正在尝试根据字母表在表格视图中创建部分,并在这些部分下按字母顺序对我的条目进行排序.

我收集了bandArray中bandArrayIndex的每个条目中的第一个字母,我现在正在尝试使用NSPredicate来计算每个字母的数量.

我按照本指南这样做了.

他们正在使用NSArray而我正在使用NSDictionary,似乎无法让它工作.谁能帮我吗?

尝试使用表视图显示视图时,应用程序崩溃.在Debugger Console中,显示以下错误:

*由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'无法使用非字符串的内容执行子字符串操作

这是我的代码

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSString *alphabet = [bandsArrayIndex objectAtIndex:section];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
    NSArray *letters = [bandsArray filteredArrayUsingPredicate:predicate];

    return [letters count];
}
Run Code Online (Sandbox Code Playgroud)

编辑:这是我的bandArray.

标题

NSMutableArray *bandsArray;

@property (nonatomic, retain) NSMutableArray* bandsArray;
Run Code Online (Sandbox Code Playgroud)

实施

// set array from plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"Bands" ofType:@"plist"];
NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];

self.bandsArray = tmpArray;

// sort array after name ascending
NSSortDescriptor *nameSorter = [[NSSortDescriptor alloc] …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsdictionary nspredicate

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

从另一个iOS中减去一个图像

任何人都知道如何创建从另一个UIImage中减去一个UIImage

例如,作为此屏幕:

在此输入图像描述

谢谢你的回复!

objective-c uiimage ios

9
推荐指数
2
解决办法
2897
查看次数