小编Gen*_*ted的帖子

请在Objective C中解释Getter和Setters

可能重复:
Setter和Getters(Noobie) - iPhone SDK

我是初学者.我刚刚开始学习iOS过去两个月,我没有任何编程背景.(虽然有点Java).任何人都可以在Objective C中解释什么是getter和setter?它们有什么用?我们为什么要使用@property@synthesize

getter setter objective-c

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

Google API - 如何将URL重定向到我的localhost

我正在使用Google OAuth在我的Phonegap应用中集成google登录功能.发生的事情是,在为我的应用程序创建客户端ID时,我必须选择"已安装的应用程序",然后将应用程序类型设置为"其他",因为我使用Phonegap创建应用程序.

这给了我两个重定向URI,如" urn:ietf:wg:oauth:2.0:oob"和" http://localhost".我不选择使用" urn:ietf:wg:oauth:2.0:oob",因为它要求用户复制代码并将其放回应用程序.我的另一个选项是重定向到localhost.

这里的问题是,当我在iPad上时,如何将URL重定向到localhost?我曾尝试使用不同的重定向URI,但Google不允许我使用它们.它仅限于重定向到localhost(或添加一些端口号),我没有其他去.

有没有人对此有任何解决方法?有没有办法完成这项任务?我被卡住了.请帮忙.

login localhost ipad cordova

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

iOS使用NSJSONSerialization在POST请求中发送JSON数据

我知道有类似的问题发布,因为我已经阅读了大多数所有这些并且仍然遇到问题.我正在尝试将JSON数据发送到我的服务器,但我不认为正在接收JSON数据.我只是不确定我错过了什么.以下是我的代码......

将数据发送到服务器的方法.

- (void)saveTrackToCloud
{
    NSData *jsonData = [self.track jsonTrackDataForUploadingToCloud];  // Method shown below.
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSLog(@"%@", jsonString);  // To verify the jsonString.

    NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:http://www.myDomain.com/myscript.php] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];
    [postRequest setHTTPMethod:@"POST"];
    [postRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [postRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [postRequest setValue:[NSString stringWithFormat:@"%d", [jsonData length]] forHTTPHeaderField:@"Content-Length"];
    [postRequest setHTTPBody:jsonData];

    NSURLResponse *response = nil;
    NSError *requestError = nil;
    NSData *returnData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&requestError];

    if (requestError == nil) {
        NSString *returnString = [[NSString …
Run Code Online (Sandbox Code Playgroud)

php post json ios nsjsonserialization

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

当字符长度改变时,保持UILabel在UIView中居中.iOS,Objective C

我有一个UILabel我在屏幕中间居中.数值最多可包含三位数.例如500.

我的问题是,当值改变时,它会使UILabel位置偏离中心.

在下面的图像中,您将看到当值等于3位时,滑块标签看起来居中,当滑块标签值为12时,标签看起来偏离中心.

我需要UILabel调整自己总是在中心UIView.

我已经尝试了下面的代码添加到我UILabel没有运气.

在此输入图像描述 在此输入图像描述

self.myCircleSliderValueLabel.font = sliderValueFont;
self.myCircleSliderValueLabel.textColor = [UIColor colorWithRed:103/255.0 green:187/255.0 blue:230/255.0 alpha:1.0];;
self.myCircleSliderValueLabel.numberOfLines = 0;
self.myCircleSliderValueLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.myCircleSliderValueLabel.text = @"400";
[self.myCircleSlider addSubview:self.myCircleSliderValueLabel];

self.myCircleSliderValueLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin |  UIViewAutoresizingFlexibleRightMargin; 
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiview uilabel ios

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

无法在iOS中连接SQLite数据库

我是SQLite和iOS的新手.我正在学习如何在iOS中使用SQLite的基本教程:

http://www.switchonthecode.com/tutorials/using-sqlite-on-the-iphone#comment-11617

在上面的链接中,他们将数据库指定为:

sqlite3 *database;

int result = sqlite3_open("/myExampleDatabase.db", &database);
Run Code Online (Sandbox Code Playgroud)

但是当我使用上面的代码替换我的数据库名称时,我得到了后续alertview中指定的错误.

我的问题是,我是否必须将数据库文件添加到我的资源文件夹中?如果没有,我是否必须将我的数据库文件放在iOS可访问的地方?

sqlite ios

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

App崩溃说集合表达式类型UIView*'可能无法响应'countByEnumeratingWithState:object:count"'

我有一个UIImageViewtableView内部,并希望在单击该行时以编程方式删除它.

   -(void) tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {

            for (UIView *subview in  tableView)
            {
                if([subview isKindOfClass:[UIImageView class]])
                {
                 [subview removeFromSuperview];
                }
            }
}
Run Code Online (Sandbox Code Playgroud)

当我点击表格行时,应用程序崩溃了.Warning : Collection expression type UIView* may not respond to countByEnumeratingWithState:object:count" 应用程序崩溃提供相同的消息.我错过了什么?我只粘贴了相关的代码部分.

iphone objective-c uitableview uiview ios

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

在后台杀死应用程序时删除数据.

我有一个应用程序,我正在保存数据,但当应用程序在后台被杀死时,我必须删除所有已保存的数据.

我尝试过使用这种方法:

- (void)applicationWillTerminate:(UIApplication *)application
Run Code Online (Sandbox Code Playgroud)

但它不起作用.有人可以建议我怎么做吗?

uiapplicationdelegate ios ios6 ios7 uibackgroundtask

0
推荐指数
1
解决办法
891
查看次数