小编sma*_*nja的帖子

如何在添加新项目时自动滚动tableview?

如何在添加新项目时自动滚动tableview?

我尝试使用

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath 
              atScrollPosition:(UITableViewScrollPosition)scrollPosition 
                      animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)

但我无法理解.

你能提供样品代码吗?

iphone objective-c uitableview ios4 ios

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

如何使用单个按钮和单个操作方法显示/隐藏UIPopoverController

以下方法与导航栏按钮相关联.按下按钮时,显示aUIPopoverController

- (IBAction) showTablePopUp:(id) sender {

if (self.tablesPopoverController == nil) {

    TablesPopOverViewController *tables = [[TablesPopOverViewController alloc]initWithNibName:@"TablesPopOverViewController" bundle:[NSBundle mainBundle]]; 

    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:tables]; 

    popover.delegate = self;
    popover.popoverContentSize=CGSizeMake(280.0, 327.0);
    [tables release];

    self.tablesPopoverController = popover;
    [popover release];
}

[self.tablesPopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


}
Run Code Online (Sandbox Code Playgroud)

我想要做的是在第二次按下按钮时隐藏弹出窗口:

  1. 点击 - 显示弹出窗口
  2. 单击 - 隐藏弹出框

我该怎么做?

objective-c uipopovercontroller ios

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

使用BradLarson/GPUImage的图像过滤效果**问题

我想为UIImage添加不同的效果.目前我正在尝试使用GUIImage库.https://github.com/BradLarson/GPUImage 但是,我无法运行提供的大部分示例.只有我的工作示例是FilterShowcase它很棒.

但问题是,它的工作只与相机有关.我想要的是将静态图像加载到UIImageView并应用这些过滤器.

我试过了,但无法做到.

这是我尝试的方式

  - (void)setupFilter;
{
//    videoCamera = [[GPUImageVideoCamera alloc]  initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
////    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
//    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;


UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)];

imgView.Image=[UIImage imageNamed:@"WID-small.jpg"];

[self.view addSubview:imgView];

BOOL needsSecondImage = NO;

switch (filterType)
{
    case GPUIMAGE_SEPIA:
    {
        self.title = @"Sepia Tone";
        self.filterSettingsSlider.hidden = NO;

        [self.filterSettingsSlider setValue:1.0];
        [self.filterSettingsSlider setMinimumValue:0.0];
        [self.filterSettingsSlider setMaximumValue:1.0];

        filter = [[GPUImageSepiaFilter alloc] init];

        sourcePicture = [[GPUImagePicture alloc] initWithImage:imgView.image smoothlyScaleOutput:YES];
        [sourcePicture processImage];            
        [sourcePicture addTarget:filter]; …
Run Code Online (Sandbox Code Playgroud)

objective-c ios4 ios

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

如何通过内置耳机扬声器播放音频

我已经看到像WhatsApp这样的应用程序具有仅当用户将设备靠近耳朵时才通过耳机(电话扬声器)播放音频剪辑的功能.否则通过普通的内置扬声器播放.

我正在使用MPMoviePlayer播放音频剪辑.

我确实在互联网上经历了许多类似的问题和答案,并且所有答案都说将AudioSession类别设置为PlayAndRecord.而已.

我做了同样的事,但无法得到我想得到的确切结果.

// Audio Player
self.audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
self.moviePlayer = [[MPMoviePlayerController alloc] init];
self.moviePlayer.view.hidden = YES;

//    AVAudioSessionPortDescription *routePort = self.audioSession.currentRoute.outputs.firstObject;
//    NSString *portType = routePort.portType;
//    
//    if ([portType isEqualToString:@"Receiver"]) {
//        [self.audioSession  overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
//    } else {
//        [self.audioSession  overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
//    }
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我,只有当用户打开设备时,我才能通过耳机扬声器修改音源来播放音频的方式和位置?

iphone objective-c mpmovieplayercontroller ios avaudiosession

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

具有 IP 地址的通用链接

我在我的项目中实现了通用链接,但测试服务器没有域名。

按照官方文档中的步骤操作:https : //developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html

我在关联域中填写了“applinks:{ip address}”,但它不起作用。

通用链接功能是否必须使用域名?

objective-c ios ios-universal-links

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

Objc_msgSend和app崩溃

当我尝试在模拟器(3.1.3,Xcode 3.1.4)上启动我的应用程序时,它显示我objc_msgSend并且应用程序无法启动.这只发生在我分配NSMUtable数组时 这是我的代码部分,在viewDidLoad中,

 -(void)viewDidLoad{

   locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut"];
   str1=[locationArray objectAtIndex:0];
   str2=[locationArray objectAtIndex:1];

      [super viewDidLoad];
 } 
Run Code Online (Sandbox Code Playgroud)

然后我想在以下方法中使用locationArray对象;

 -(CLLocationCoordinate2D) addressLocation1{

double latitude = 0.0;
double longitude = 0.0;
NSString *str= [locationArray NSString *str= [locationArray objectAtIndex:0];

    //NSString *str= @"new delhi"

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                       [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];


if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
    latitude = [[listItems objectAtIndex:2] doubleValue];
    longitude = [[listItems objectAtIndex:3] doubleValue];
}
else …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsarray ios

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

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

如何从文档目录加载PDF?

我可以使用此代码从Resources文件夹加载pdf文件列表(所有pdf文件).

 NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:@"pdf" inDirectory:nil];
Run Code Online (Sandbox Code Playgroud)

但我找不到从Documents Directory加载pdf文件列表的方法.以下代码行一次只能加载一个 pdf.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file = [documentsDirectory stringByAppendingPathComponent:@"test.pdf"];
NSURL *urlPdf = [NSURL fileURLWithPath: file];
Run Code Online (Sandbox Code Playgroud)

如何从Documents Directory加载所有pdf文件

你能给我一个代码示例吗?

iphone objective-c ios4 ios

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

如何检测哪个 UILabel 被点击?

我有三个 UILabel。我想检测哪个标签被点击,然后检索该标签的字符串值。这就是我正在尝试的方式,我只能设法检测被点击的位置,但我无法检测被点击的标签。

标签创建

for (NSInteger i=1; i<=[pdfs count]; i++){
    UILabel *newLabel=[[UILabel alloc] init];
    newLabel.text = [NSString stringWithFormat:[[pdfs objectAtIndex:(i-1)] lastPathComponent]];
    newLabel.frame = CGRectMake(10, 60*i, 320, 20);
    newLabel.tag=i;
    newLabel.font = [UIFont systemFontOfSize:20.0f];
    newLabel.backgroundColor = [UIColor clearColor];
    newLabel.userInteractionEnabled = YES;
    [self.view addSubview:newLabel];
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [newLabel addGestureRecognizer:singleTap]; 
    [newLabel release], newLabel=nil;
    [singleTap release];
} 
Run Code Online (Sandbox Code Playgroud)

检测水龙头

 - (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
Run Code Online (Sandbox Code Playgroud)

{

CGPoint location;
location = [recognizer locationInView:self.view];

NSString *documentName;
if(location.y<150.0){
    documentName = [[pdfs objectAtIndex:0] lastPathComponent]; 
}
else{
    documentName = [[pdfs …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios4 ios

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

使用来自Objective C类的参数调用Swift函数

我有一个快速编写的库类,应该在现有的Objective-C代码中使用。我创建了桥接头,并在.h中定义了@class MySwiftClass,并在.m中导入了“ -Swift.h”

迅速的班级与此类似

@objc class MySwiftClass: NSObject {
    var firstName : String
    var lastName: String

    public init(firstName: String, lastName: String) throws {
        guard !firstName.isEmpty && !lastName.isEmpty else { throw SOME_ERROR }
        self.firstName = firstName
        self.lastName = lastName
        super.init()
    }


func methodWithParams(city: String, suburb: String) throws -> String {
        return city + suburb
    }
Run Code Online (Sandbox Code Playgroud)

我遇到了两个问题。

  1. 不知道如何init在Objective-C类上调用swift 函数。我试过了MySwiftClass *myClass = [MySwiftClass init];。到目前为止,该应用可以编译。但是不知道如何传递参数。

  2. 我也想myClass.methodWithParams(city:"My city", suburb:"My country")在Objective-C类中访问。

感谢帮助!

objective-c ios swift

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