我正在使用UIAlertView的新iOS 5功能之一.我像这样创建一个UIAlertView:
UIAlertView *scanCode = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Some Title", @"") message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:NSLocalizedString(@"OK", @""), nil];
[scanCode setAlertViewStyle:UIAlertViewStylePlainTextInput];
scanCode.tag = 1234;
[scanCode show];
[scanCode release];
Run Code Online (Sandbox Code Playgroud)
我现在使用的代表是:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == 1234) {
if (buttonIndex == 1)
{
//do something
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想模拟回车键,所以当用户按下键盘返回时,按下警报的OK按钮就会发生同样的事情.我怎样才能做到这一点?
提前致谢!
我想创建一个bash文件(.sh),它执行以下操作:
我把脚本称为./download.sh www.blabla.com/bla.jpg
如果文件已下载,脚本必须回显...
我怎样才能做到这一点?我知道我可以使用errorlevel但是我是linux新手所以......
提前致谢!
我目前正在开发一个iPad项目,我需要这个功能让用户用手写笔在一张纸上书写.
我测试了几个手指,发现竹子是最好的.他们还有一个免费的应用程序,您可以用它来编写.
我面临的问题是我使用的方法不能提供平滑的曲线.竹纸应用程序提供完美的线条.这是我到目前为止的代码:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsBeginImageContext(self.frame.size);
// draw accumulated lines
if ([self.lines count] > 0) {
for (Line *tempLine in self.lines){
CGContextSetAlpha(context, tempLine.opacity);
CGContextSetStrokeColorWithColor(context, tempLine.lineColor.CGColor);
CGContextSetLineWidth(context, tempLine.lineWidth);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextAddPath(context, tempLine.linePath);
CGContextStrokePath(context);
}
}
//draw current line
CGContextSetAlpha(context, self.currentLine.opacity);
CGContextSetStrokeColorWithColor(context, self.currentLine.lineColor.CGColor);
CGContextSetLineWidth(context, self.currentLine.lineWidth);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextBeginPath(context);
CGContextAddPath(context, self.currentLine.linePath);
CGContextStrokePath(context);
UIGraphicsEndImageContext();
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint cPoint = [touch locationInView:self];
CGPathMoveToPoint(self.currentLine.linePath, NULL, cPoint.x, cPoint.y); …Run Code Online (Sandbox Code Playgroud) 我在表单上使用多个UISliders,我只想要一种方法来跟踪滑块的变化.
现在我有一个方法:
- (IBAction) slider1ValueChanged:(UISlider *)sender {
somelabel.text = [NSString stringWithFormat:@" %.1f", [sender value]];
}
Run Code Online (Sandbox Code Playgroud)
但是因为我使用多个滑块,我想使用switch语句来触发特定的滑块,所以例如如果我有2个滑块,并且它们都使用上面的ValueChanged方法,我想要类似的东西:
- (IBAction) slider1ValueChanged:(UISlider *)sender {
switch(SLIDERID)
case SLIDER1:
blabla;
break;
case SLIDER2:
update other label;
break;
case default:
break;
somelabel.text = [NSString stringWithFormat:@" %.1f", [sender value]];
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我?
提前致谢!
我有一个HTML文件,其中包含以下内容:
<img src="MATCH1" bla="blabla">
<something:else bla="blabla" bla="bla"><something:else2 something="something">
<something image="MATCH2" bla="abc">
Run Code Online (Sandbox Code Playgroud)
现在我需要一个正则表达式匹配MATCH1和MATCH2
此外,HTML包含多个这样的部分,因此它可以在HTML的1,2,3中x次.
当我说:
<img\s*src="(.*?)".*?<something\s*image="(.*?)"
Run Code Online (Sandbox Code Playgroud)
它与它不匹配.我在这里错过了什么?
提前致谢!
在我的AppDelegate中,我有以下代码:
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *itemsNavigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
Run Code Online (Sandbox Code Playgroud)
如何将UIVNagigationBar的背景颜色设置为绿色?
如果我做:
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
Run Code Online (Sandbox Code Playgroud)
从viewController1,这没有任何效果.
提前致谢!
更新:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"MyTitle", @"");
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
[self.parentViewController.navigationController.navigationBar setTintColor:[UIColor greenColor]];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
两者都没有效果
我已将我的应用程序升级到 Swift 2.0,从那时起,NSFetchedResultsController 在 iOS 8.4 上无法正常运行(在 iOS 9 中,它按预期工作)
场景: - 添加一个新实体 - 行出现在表视图中 - 实体的属性已更改,因此它不应与 fetchedtesultscontroller 的谓词匹配 - 该行不会从表视图中消失...
我可以看到 beginUpdates,使用删除类型调用 didChangeObject,并调用 endUpdates() 。我的缓存为零。
这是 iOS 8.4 的 xCode 7 中的已知错误吗?(有趣的是,有时它确实有效,但大多数时候它不起作用,这对我的应用程序至关重要......)
提前致谢!
ps我尝试了他们在网上说的 if (indexPath != newIndexPath) 东西,但结果相同......
我有一个json:
[
{
"id" : 42422422,
"created" : 1329684013,
"name" : "Test"
},
{
"id" : 42422423,
"created" : 1329684015,
"name" : "Test 123"
},
{
...
}
]
Run Code Online (Sandbox Code Playgroud)
解析这个问题,但是当网络服务器出错时,会返回此JSON:
{
"error" : {
"code" : "511",
"message" : "JSON error",
"extra" : {
"some" : "text",
"someextra" : "text"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试过用这个:
if ([jsonArray valueForKey:@"error"] != nil) {
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为如果我输出的值是'null'的数组
我怎么检查这个?(我知道我可以使用NSRange,但我认为必须有更好的方法吗?
我像这样解析JSON:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error: &e];
Run Code Online (Sandbox Code Playgroud)
responseData来自NSURLConnection的connectionDidFinishLoading方法.