小编Man*_*nni的帖子

如何向UIView添加触摸事件?

如何向UIView添加触摸事件?
我尝试:

UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, nextY)] autorelease];
[headerView addTarget:self action:@selector(myEvent:) forControlEvents:UIControlEventTouchDown];
// ERROR MESSAGE: UIView may not respond to '-addTarget:action:forControlEvents:'
Run Code Online (Sandbox Code Playgroud)

我不想创建子类和覆盖

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)

events objective-c touch uiview ios

272
推荐指数
9
解决办法
32万
查看次数

Xcode 4:创建IPA文件而不是.xcarchive

在Xcode 3.2.5中,我使用"Build and Archive"创建一个IPA文件.在Xcode 4中,您可以使用"Product - > Archive"将应用程序归档到.xcarchive包中.

如何使用Xcode 4创建.ipa文件?

xcode ios xcode4

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

Xcode Debugger:变量的视图值

我在UITableViewController中的代码:

delegate.myData = [myData objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)

我怎样才能看到的值delegate.myDataindexPath.row在调试?delegate.myData应该是一个数组和indexPath.row一个int.我只能看到物体的内存地址delegate,并indexPath在哪儿呢?myDatarow

替代文字

iphone debugging xcode objective-c ios

99
推荐指数
5
解决办法
12万
查看次数

CALayer:仅在一侧添加边框

我可以用这种方式为CALayer添加边框:

[webView.layer setBorderColor: [[UIColor colorWithRed:0.6 green:0.7 blue:0.2 alpha:1] CGColor]];
[webView.layer setBorderWidth: 2.75];   
Run Code Online (Sandbox Code Playgroud)

但是,是否可以仅在一侧添加边框?我只需要底部的边框.或者我可以用其他属性来达到这个目的,例如框架,边界,面具,......?

在此输入图像描述

谢谢你的帮助!


b控制-V

        UIWebView *webView = [[UIWebView alloc] init];
        CALayer *webViewLayer = webView.layer;

        // now you can do a lot of stuff like borders:
        [webViewLayer setBorderColor: [[UIColor greenColor] CGColor]];
        [webViewLayer setBorderWidth: 2.75];    
Run Code Online (Sandbox Code Playgroud)

请查看CALayer文档:https: //developer.apple.com/documentation/quartzcore/calayer

看看这里:http: //iosdevelopertips.com/cocoa/add-rounded-corners-and-border-to-uiwebview.html

iphone core-animation objective-c calayer

62
推荐指数
5
解决办法
6万
查看次数

如何将"SEL"和"id"转换为NSString?

id parent;
SEL selector;

// lot's of code...

if ([parent respondsToSelector:selector]) {

}
else {
    // This doesn't work:
    NSString *errorMessage = [NSString stringWithFormat:@"%@ in class %@ doesn't exist!", selector, parent];
}
Run Code Online (Sandbox Code Playgroud)

如何将"SEL"和"id"转换为字符串?

objective-c selector nsstring ios

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

如何取消/重置UIGestureRecognizer

我该如何取消或重置UIGestureRecognizer?问题是,如果我设置waitForSomethingNO手势时,下一个事件是UIGestureRecognizerStateChanged.但第一件事应该是UIGestureRecognizerStateBegan.

我的代码:

- (void) panned:(UIPanGestureRecognizer *) recognizer {
    if (waitForSomething) {
        // cancel or reset the recognizer!
        // because the next event should be UIGestureRecognizerStateBegan and not UIGestureRecognizerStateChanged
        return;
    }

    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:
            // important initialisation code
            break;

        case UIGestureRecognizerStateChanged:
            // do something
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

iphone objective-c uigesturerecognizer ios

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

UINavigationController:如何取消后退按钮事件?

在我的UIViewController我有UINavigationController一个默认后退按钮.当用户单击后退按钮时,将显示一条警告消息:"你真的想回去吗?".我知道,无法捕获后退按钮事件.它只能使用viewWillDisappear并设置一个标志:

- (void)viewWillDisappear:(BOOL)animated {
    if (backBtnPressed) {
        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Question" message:@"Do you really want to go back?" delegate:self cancelButtonTitle:@"No" otherButtonTitles: @"Yes", nil] autorelease];
        [alert show];   
    }
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        // don't go back!
        // cancel the back button event
    }
    else if (buttonIndex == 1) {
        // go back
    }
}
Run Code Online (Sandbox Code Playgroud)

但是这个代码我没有机会!我无法阻止后退按钮事件,不是吗?

我是否必须编写自己的后退按钮并将其设置为leftBarButtonItem?还是有人有个好主意吗?:-)

谢谢你的帮助!

iphone uinavigationcontroller ios

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

Xcode 4&three20&create IPA archive:没有这样的文件或目录

在Xcode 3.2.5中,我使用"Build and Archive"创建一个没有任何问题的IPA文件.我怎么能在Xcode 4中做到这一点?我想我必须使用"Product - > Archive",但我在three20框架中收到了100多条错误消息.大多数是"没有这样的文件或目录".("产品 - >构建 - >构建存档"工作.没有错误.)

例如,这是第一条错误消息:

../scripts/Protect.command: line 23: cd: /Users/[USERNAME]/Library/Developer/Xcode/DerivedData/[PROJECTNAME]-blabla/ArchiveIntermediates/[PROJECTNAME]/BuildProductsPath/Release-iphoneos/../three20/Three20Core: No such file or directory
Run Code Online (Sandbox Code Playgroud)

该路径"/[PROJECTNAME]/BuildProductsPath/three20/"确实不存在,但此路径存在:"/[PROJECTNAME]/three20/"

我能做什么?

iphone xcode three20 xcode4

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

如何使用Interface Builder添加导航控制器?

1.步骤:创建一个新的UIViewController:
- Xcode - > New File ... - > Cocoa Touch Class - > UIViewController
- 名称:MyViewController

2.步骤:将"导航控制器"(UINavigationController)从库拖放到MyViewController.xib

替代文字

3.Step:我确定,我必须做一些事情来正确连接导航控制器,不是吗?

4.Step:尝试将新的View Controller作为模态对话框启动:

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
NSLog(@"navContr: %@", myViewController.navigationController);
[self.navigationController presentModalViewController: myViewController animated:YES]; 
Run Code Online (Sandbox Code Playgroud)

结果:"navContr:nil"

5.Step:你可以看到新的模态视图(MyViewController),但没有NavigationController,也没有UINavigationBar.

非常感谢您的帮助!


更新1:

6.Step:我将一个新的UIViewController(ViewNavi2)设置为"Root View Controller":
替代文字

7.Step:IBOutlet UINavigationController *navigationController在类MyViewController中定义一个并配置xib:Navigation Controller - > Connections - > Referencing Outlets

但我的导航控制器仍然是零:-(

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
NSLog(@"navContr: %@", myViewController.navigationController);
// -> "navContr: nil"
Run Code Online (Sandbox Code Playgroud)

iphone objective-c interface-builder uinavigationcontroller ios

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

在UIWebView中停止视频

在我的iPad应用程序中,我有一个模态视图(UIViewController具有模态演示风格UIModalPresentationPageSheet)

视图内部是一个带有HTML页面和嵌入式YouTube视频的UIWebView.如果我启动视频并关闭视图,则视频不会停止.音频继续,您可以在状态栏中的"电池图标"旁边看到一个小"播放图标".

我怎么能停止视频?

iphone objective-c uiwebview ipad

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