Tag: Objective C

NSURLConnection sendAsynchronousRequest:queue:completionHandler在iOS 4.3中不起作用

我在我的应用程序中使用[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 。 通过使用这个我的应用程序在iOS 4.3中终止,但它在iOS 5.0中运行良好。 如何在iOS 4.3中使用它可以任何人帮助我。

升级到Xcode 4.2之后为什么MKAnnotation会显示警告

在Xcode 4.1中没有问题,但升级到Xcode 4.2我得到以下警告: Property ‘title’ ‘copy’ attribute does not match the property inherited from ‘MKAnnotation’ Property ‘subtitle’ ‘copy’ attribute does not match the property inherited from ‘MKAnnotation’ 我的代码: @interface MyAnnotation : NSObject { CLLocationCoordinate2D coordinate; NSString *subtitle; NSString *title; } @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; @property (nonatomic, retain) NSString *subtitle; @property (nonatomic, retain) NSString *title; […]

UIButton在UItableViewCell中不起作用

我有一个由标签和两个按钮组成的视图,我将其命名为UIView *footerView ,因为我在表视图的最后一部分实现了这一点。 我有这个视图通过使用[cell.contentView addSubview: footerView]成为indexPath.section = 3的视图 这是我的问题: 我可以在单元格内看到视图。 但我无法点击按钮,因为单元格被选中而不是按钮(在单元格内)。 我该如何克服这个问题? 我的按钮甚至无法选择! 这是代码…在cellForRowAtIndexPath: if (section == 3){ cell = nil; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; if (indexPath.row ==0){ cell.contentMode = UIViewContentModeScaleToFill; [cell.contentView addSubview:self.footerView]; } } 页脚视图(如果有人需要看到这个): UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 3, 300, 44)]; textView.text = @”Terms and Conditions: Lorem ipsum […]

带有类别的NSManagedObjects

我认为将NSManagedObject自定义代码放在子类的类别中是一种常见的做法,因为Xcode会在编辑模型时覆盖生成的子类。 我只是想证实这一点。 我见过一些例子,人们说将类别与已经在类层次结构中实现的方法结合起来是不好的。 我不确定这是否仅适用于具有实际类别的类具有已实现的方法或在所有情况下的情况。

AVPlayer跳过video的开头

当我试图在预滚动后立即播放时,我正在尝试AVPlayer跳过我正在播放的video的前0.5秒。 首先,我创建了播放器: self.videoPlayer = [[AVPlayer alloc] init]; 然后,我将播放器项目添加到播放器并添加一个观察者来检查并查看该项目何时准备好: [self.videoPlayer addObserver:self forKeyPath:@”currentItem” options:0 context:kBLCurrentPlayerItemStatusContext]; [self.videoPlayer replaceCurrentItemWithPlayerItem:self.currentVideoPlayerItem]; 当观察到玩家项目时,我将检查玩家是否准备好玩。 如果还没准备好玩,我会添加一个观察者来确保它已经准备好了: -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ … } else if (context == kBLCurrentPlayerItemStatusContext) { [self.videoPlayer removeObserver:self forKeyPath:@”currentItem” context:&kBLCurrentPlayerItemStatusContext]; if ([self.videoPlayer status]==AVPlayerStatusReadyToPlay) { [self prerollVideoPlayer]; } else { [self.videoPlayer addObserver:self forKeyPath:@”status” options:0 context:&kBLVideoPlayerStatusContext]; } } … 当观察到玩家状态准备好玩时,我会预先注册玩家: -(void)observeValueForKeyPath:(NSString […]

如何以编程方式检测自动引用计数?

这可能是一个愚蠢的问题,但我只是想知道。 我希望我的代码能够以编程方式检测ARC是否已启用。 我怎么做? 有没有我可以检查的旗帜? 实际上问题是,我写了一个开源库。 我已经使用了release并retain在其中。 如果其他人使用我启用ARC的库文件,我不希望他们得到任何错误。 我该怎么做到这一点? 或者有没有可能的方法我可以提供任何工具来编译我的库之前使用它?

ios – Objective-c只有UITableView的第一个单元格没有显示我添加的标签

我正在尝试从plist中添加1到9的数字到UITableView中的每个单元格。 然而,第一个视图没有显示任何内容,第一个视图显示在第二个单元格中,2显示在第三个单元格中,依此类推。 我通过添加NSLog(@”test”);做了一些测试NSLog(@”test”); 在if(cell==nil)里面if(cell==nil)但只有7个“test”被打印,而有9个单元格。这是否意味着if(cell==nil)内部的代码不会对第一个和最后一个单元格执行? 有人在乎解决这个问题吗? 🙁 // Customize the appearance of table view cells. – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @”Cell”; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSLog(@”hi”); //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell = [self getCellContentView:CellIdentifier]; //add another textfield NSString *rankpath = [[NSBundle […]

在CAKeyFrameAnimation期间检测碰撞

在CAKeyFrameAnimation期间沿着路径行进时,是否可以检测到两个UIImageViews的碰撞? 如果是这样,我已经尝试了多种方法,包括在动画期间检查CGRects是否发生碰撞 – 但是在CAKeyFrameAnimation期间找不到合适的方法来执行方法并尝试检测路径和UIImageView的碰撞。

如何以编程方式添加UIBarButtonItem?

以编程方式添加UIBarButtonItem的正确方法是什么? 在我的情况下,我正在尝试将一个添加到rightBarButtonItem ,我一直在控制器层次结构中跳跃,但我似乎无法让按钮显示在任何地方。 这是我目前的代码: – (void)viewDidLoad { [super viewDidLoad]; [self.navigationItem setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile:@”Barcode-White.png”] style:UIBarButtonItemStylePlain target:self action:@selector(scanEquipment:)] autorelease]]; } 我希望有人能引导我走向正确的方向。 我试图调用它的控制器是3级。所以, UITabBarController – > UIViewController (Settings, 1st level) – > UIViewController (Vehicle, 2nd level) – > UIViewController (Inventory, 3rd level) 。 无论如何,提前感谢任何帮助!

如何识别iOS设备上收到的udp数据包的发件人IP地址?

如何找出运行iOS 3.2或更高版本的设备上收到的udp数据包的发件人IP地址? 例如,如果在计算机上使用Python,我将使用SocketServer.UDPServer ,它使用SocketServer.UDPServer的子类来定义handle回调。 当数据包到达时,将调用回调并且发送方的IP地址将位于self.client_address ,其中self是SocketServer.BaseRequestHandler实例。 不幸的是,在Objective C中编程并使用为iOS提供的框架时,我不知道如何提取此信息或获取对相关ip头的访问权限。 现在我唯一的解决方案是在udp数据包的主体上显式写入发送者的ip,但是如果我不需要,我宁愿不依赖发送者将信息放在那里。