小编Mat*_*uch的帖子

在应用程序内购买

我是iPhone开发的新手.

如果我想通过Apple只在应用程序中购买图像 - 在应用程序购买付款模式.那么这个方法会是什么?

注意:不要购买整个应用程序.

提前致谢.

iphone objective-c in-app-purchase

5
推荐指数
2
解决办法
898
查看次数

dequeueReusableCellWithIdentifier如何工作?

我想要一些精确的dequeueReusableCellWithIdentifier:kCellIdentifier.如果我理解得很好,下面的NSLOG应该打印一次.但事实并非如此.那么dequeueReusableCell有什么意义呢?它只对定制单元有效吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *kCellIdentifier = @"UITableViewCellStyleSubtitle3";


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
    if (cell == nil)
    {
        NSLog(@"creation of the cell");
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellIdentifier] autorelease];
    }

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = [[self.table objectAtIndex:indexPath.row] objectForKey:kTitleKey];


    [cell setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.6]];
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

iphone uitableview ios

5
推荐指数
2
解决办法
2904
查看次数

绘制文本并添加到UIImage iOS 5/6

我有一个文本框,我希望将书面文本添加到UIImage.

如何将NSString绘制为UIImage?

我搜索过,发现了很多例子,但没有一个例子.Xcode只是给了我很多错误.

简单地说,我想绘制一个NSString到UIimage.UIImage应与预定义的UIImageView大小相同,并放在中心位置.

有任何想法吗?

core-graphics draw uiimage ios

5
推荐指数
1
解决办法
6072
查看次数

UIPickerView显示错误的标题

我的应用程序是一个带有多组分拾取轮的转换器.它用于转换一些变量.您可以看到的数字仅用于测试,没有什么重要的.

- (void)viewDidLoad
{
  [super viewDidLoad];
  _convertFrom = @[@"One (1)", @"Two (2)",
  @"Three (3)", @"Four (4)", @"Five (5)"];

  _convertRates = @[ @1.0f, @2.0f, @3.0f,
  @4.0f, @5.0f];

  _convertTo = @[@"One (1)", @"Two (2)",
  @"Three (3)", @"Four (4)", @"Five (5)"];

_convertRates = @[ @1.0f, @2.0f, @3.0f,
@4.0f, @5.0f];

}
Run Code Online (Sandbox Code Playgroud)

我在iOS 6模拟器中测试应用程序时显示的数字有一个小问题.正如你在这里看到的:

截图

http://imgur.com/q4uxm

当我试着沿着列表走下去时,数字就会改变.但它们的价值却没有.如果有人有时间检查出来并且可能找到解决方案,那将非常有帮助:)

这是在这种情况下可能很重要的其余代码:

#pragma mark -
#pragma mark PickerView DataSource

- (NSInteger)numberOfComponentsInPickerView:
 (UIPickerView *)pickerView
{
return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:    (NSInteger)component
{
if (component == 0)  {
    return [_convertFrom …
Run Code Online (Sandbox Code Playgroud)

uipickerview ios

5
推荐指数
1
解决办法
818
查看次数

NSDate dateByAddingTimeInterval减去天数错误地更改时间

我错过了一些关于NSDate dateByAddingTimeInterval如何使用几天的内容?这是我从特定日期(AIDate)减去33天的代码.AIDate的时间值为00:00 PST.

activityOne.ActivityDateTime = [AIDate dateByAddingTimeInterval:-33*24*60*60];
Run Code Online (Sandbox Code Playgroud)

如果AIDate等于太平洋标准时间4-9-2013 00:00,则上述代码将减去33天和1小时,其工作时间为太平洋标准时间3-6-2013 23:00.

iphone cocoa-touch objective-c nsdate ios

5
推荐指数
2
解决办法
3980
查看次数

UIButton自定义边框中的Tintcolor

我为圆形自定义边框创建了UIButton的子类:

- (void)drawRect:(CGRect)rect
{
    [[self layer] setCornerRadius:CORNER_RADIUS];
    [[self layer] setMasksToBounds:YES];   
    [[self layer] setBorderWidth:1];
    [[self layer] setBorderColor:self.tintColor.CGColor];
    [self.imageView setTintColor:self.tintColor];
}
Run Code Online (Sandbox Code Playgroud)

问题是当出现一个popover时,自定义边框与tintColor的其他控件的行为不同:

在此输入图像描述

在此输入图像描述

我怎么处理它?

非常感谢

objective-c uibutton tintcolor ios7

5
推荐指数
1
解决办法
819
查看次数

如何将文件从URL复制到文档文件夹?

我需要从URL复制文本文件并将其放置/覆盖在我应用程序的文档文件夹中,然后将其读回数据变量。我有以下代码:

NSData *data;

//get docsDir
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir=[paths objectAtIndex:0];

//get path to text.txt
NSString *filePath=[docsDir stringByAppendingPathComponent:@"text.txt"];

//copy file
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;

if([fileManager fileExistsAtPath:filePath]==YES){
    [fileManager removeItemAtPath:filePath error:&error];
}

NSString *urlText = @"http://www.abc.com/text.txt";

if (![[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    [fileManager copyItemAtPath:urlText toPath:filePath error:NULL];
}

//Load from file
NSString *myString=[[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];

//convert string to data
data=[myString dataUsingEncoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)

它以良好的方式构建和遵循,但是我无法在文档文件夹中创建text.txt文件,然后将任何内容传递给我的数据变量。我是IOS和Xcode的新手,任何线索将不胜感激。谢谢!!

iphone objective-c nsfilemanager

5
推荐指数
1
解决办法
3306
查看次数

试图在Swift中使用Objective-C编写的委托方法抛出"无法找到协议声明"

我有一个使用Salesforce SDK的现有Sample Objective-C应用程序.我试图将它转换为一次使用Swift一类.Salesforce SDK有一个名为'SFRestRequest.h'的类,它具有'SFRestDelegate'委托.

在Objective C中,我有一个名为'RootViewController.h'的类,它是UITableViewController的子类.它实现了SFRestDelegate.它工作正常.

//RootViewController.h
#import <UIKit/UIKit.h>
#import "SFRestAPI.h"

@interface RootViewController : UITableViewController <SFRestDelegate> {

    NSMutableArray *dataRows;
    IBOutlet UITableView *tableView;    

}
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建一个RootVC.swift文件来替换RootViewController Objective-c类.

我有一个桥接头文件导入所有在objective-c中导入的头文件

//SwiftForce-Bridging-Header.h 
#import "SFRestAPI.h"
#import "SFRestRequest.h"
Run Code Online (Sandbox Code Playgroud)

我的RooVC.Swift文件如下所示:

import UIKit

class RootVC: UITableViewController,SFRestDelegate {
 ..
..
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我命令+单击SFRestDelegate,它将正确进入协议实现.但是,如果我尝试构建,我得到.." 找不到协议声明SFRestDelegate错误!

SWIFT_CLASS("_TtC10SwiftForce6RootVC")
@interface RootVC : UITableViewController <SFRestDelegate>
@property (nonatomic) NSArray * dataRows;
- (instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER;
- (void)viewDidLoad;
- (void)didReceiveMemoryWarning;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
@end
Run Code Online (Sandbox Code Playgroud)

感谢任何帮助.您可以从以下 网址下载应用程序来测试它:https ://github.com/rajaraodv/SwiftForce

swift

5
推荐指数
1
解决办法
2995
查看次数

iOS 8 UIVisualEffect UIBlurEffect和Scaling/Moving/Resizing

我有一个UIButton的子类,我模糊,看起来很棒:

- (id)initWithFrame:(CGRect)frame
    {
        if (self = [super initWithFrame:frame])
        {
            self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.0];
            UIVisualEffect *blurEffect;
            blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

            UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
            visualEffectView.frame = self.bounds;

            [self insertSubview:visualEffectView atIndex:0];
            visualEffectView.userInteractionEnabled = NO;

            self.layer.cornerRadius = 23.8;
            self.clipsToBounds = YES;

            self.titleLabel.font = [UIFont fontWithName:@"DINCondensed-Bold" size:15.0];
        }
        return self;
    }
Run Code Online (Sandbox Code Playgroud)

这些按钮必须经常移动(平移),调整大小和缩放,当我执行这些操作时,模糊消失并变为半透明视图.如果我使用框架/中心移动,使用CGAffineTransformation会发生这种情况.

有办法解决这个问题吗?

cgaffinetransform ios uiblureffect uivisualeffectview

5
推荐指数
1
解决办法
838
查看次数

混合静态和动态UITableViewController内容会导致NSRangeException

我一直在搜索这个错误,并找到一些具有类似行为的帖子,但没有解决问题的解决方案.

我有一个UITableViewController(在SB中声明为Static),它有章节:Section 0(Recipe)是静态的4个单元格,Section 1(Flavors)应该是动态的

故事板截图

这是我用来测试的代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    rows = [[NSMutableArray alloc] initWithArray:@[@"test",@"test",@"test",@"test",@"test",@"test",@"test"]];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
    switch (section) {
        case 0:
        return 4;
        break;
        case 1:
        return rows.count;
        break;

        default:
        break;
    }

    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell;

    switch (indexPath.section) {
        case 0:
        return [super tableView:tableView cellForRowAtIndexPath:indexPath]; …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview ipad ios nsrangeexception

5
推荐指数
1
解决办法
1357
查看次数