我正在使用此代码从服务器中提取一个简单的JSON提要:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:kDataUrl parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"response: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"JSON DataError: %@", error);
}];
Run Code Online (Sandbox Code Playgroud)
有用.但是,在我更改kDataUrl上的JSON文件并验证是否在浏览器中进行了更改后,当我再次运行应用程序时,我仍然得到之前的响应.
似乎AFNetworking以某种方式缓存了旧的响应.我不想要这种行为.我想下载当前的Feed.是否需要设置一些设置或参数来关闭缓存?
我们今天刚刚在App Store中获得了应用更新批准.但是,在某些设备上,当我们下载应用程序时,即使首先完全删除它,它也会安装以前的版本.设备是否以某种方式记住旧版本?这怎么可能?一些没有用于开发的设备似乎从今天开始下载正确的版本.
这可能会发生什么?
非常简单的代码:
func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
return 1
}
func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int {
return 5
}
func tableView(tableView:UITableView!, cellForRowAtIndexPath indexPath:NSIndexPath!) -> UITableViewCell! {
let cell: BookTableViewCell = BookTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "BookCell")
println("ip: \(indexPath.row)")
cell.bookLabel.text = "test"
return cell
}
Run Code Online (Sandbox Code Playgroud)
在cell.bookLabel.text行我得到这个:
fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)
BookTableViewCell的定义如下:
class BookTableViewCell: UITableViewCell {
@IBOutlet var bookLabel: UILabel
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, …Run Code Online (Sandbox Code Playgroud) 我想我正在看一些过时的代码:
@IBAction func stockLevelDidChange(sender: AnyObject) {
if var currentCell = sender as? UIView {
while (true) {
currentCell = currentCell.superview!;
if let cell = currentCell as? ProductTableCell {
if let id = cell.productId? {
var newStockLevel:Int?;
if let stepper = sender as? UIStepper {
newStockLevel = Int(stepper.value);
}
else if let textfield = sender as? UITextField {
if let newValue = textfield.text.toInt()? {
newStockLevel = newValue;
}
}
if let level = newStockLevel {
products[id].4 = level;
cell.stockStepper.value = Double(level); …Run Code Online (Sandbox Code Playgroud) 这一直困扰着我.我不明白为什么要包含低分辨率图像.例如,如果3GS无法找到低分辨率图像,它只会使用@ 2x版本并以其原始分辨率显示它.那么为什么要通过包含所有半分辨率图像来添加应用程序的文件大小?
我的包标识符必须与iOS开发门户网站中的标识符匹配:
com.mydomain.myappname
似乎在Xcode中执行此操作的唯一方法是转到目标,构建设置,并将产品名称更改为myappname.但是,这也会导致应用程序在设备主屏幕上显示为"myappname"(在图标下方).我知道必须能够以不同的方式设置.(我希望显示"我的应用程序"而不是"myappname").我在哪里设置这个?
当我在Xcode中运行Project/Profile并选择" Zombies "时,应用程序在NSZombie detection启用了" " 的模拟器中运行.但是我该怎么想告诉我有问题呢?我看到的只是运行的分配工具和下面的统计数据.它实际上会在哪里显示Zombie检测到a?
我不需要精确的位置数据,我不希望用户看到"此应用程序想要确定您的位置"警报.我只需要确定用户的国家/地区,假设他们通过网络或Wi-Fi连接互联网.
做这个的最好方式是什么?有没有办法使用他们的IP?
这只有在有承运人的情况下才有效:
CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
NSString *mcc = [carrier mobileCountryCode];
Run Code Online (Sandbox Code Playgroud)
并且NSLocale用户可以在其设备设置中更改它并不可靠.出于同样的原因,无法使用设备的语言设置.我需要国家根据他们的实际所在地.
简单的继承,我做了一百万次:
@class AGWindowView;
@interface HelperView : AGWindowView
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Class "HelperView" defined without specifying a base class.
Run Code Online (Sandbox Code Playgroud)
好吧,显然我在指定一个基类.这里发生了什么?有没有什么方法AGWindowView不允许自己被子类化?
请考虑以下代码,该代码从plist获取字典数组:
let path = NSBundle.mainBundle().pathForResource("books", ofType: "plist")
let dict = NSDictionary(contentsOfFile: path)
let books:Array = dict.objectForKey("Books") as Array<Dictionary<String, AnyObject>> //I hate how ugly and specific this is. There has got to be a better way??? Why can't I just say let books:Array = dict.objectForKey("Books")?
let rnd = Int(arc4random_uniform((UInt32(books.count))))
let bookData:Dictionary = books[rnd]
Run Code Online (Sandbox Code Playgroud)
现在,我无法访问单个图书词典:
let title:String = bookData.objectForKey("title") //[String: AnyObject] does not have a member named 'objectForKey'
let title:String = bookData["title"] // (String, AnyObject) is not convertible to String
Run Code Online (Sandbox Code Playgroud)
找到这本书名称的正确方法是什么?
ios ×8
swift ×3
xcode ×2
afnetworking ×1
app-store ×1
caching ×1
dictionary ×1
image ×1
instruments ×1
ip-address ×1
iphone ×1
json ×1
location ×1
nsdictionary ×1
nslocale ×1
nszombie ×1
objective-c ×1
subclass ×1
uitableview ×1
uiview ×1